Tải bản đầy đủ (.pptx) (33 trang)

Session5 module6 7 generic regularexpression

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (652.88 KB, 33 trang )






!"

List#!$!
"!!ArrayList
LinkedList

Set!"!!
HashSetLinkedSetLinkHashSet"

Queue%%&"&'!!PriorityQueue"

Iterator!## #(
"

)Map'Entry"#*'
keyvalue"' #+* ",*
$"

Arrays' + #*"
&'#!"
Advanced Java / Session3 / 2 of 33
-
A Guide To Advanced Java – Module 6
.&$/
Advanced Java / Session3 / 3 of 33
A Guide To Advanced Java – Module 6


Generic
“I’d like a Cup of T”
Advanced Java / Session3 / 4 of 33
A Guide To Advanced Java – Module 6
*

* *$* ##!!'*#*'$/
# + #!!
!!"

 #!!!!#*'
!#$#+"
Advanced Java / Session5 / 5 of 29

)0)

Advanced Java / Session1 / 6 of 13
List list = new ArrayList();
Integer numberInt = new Integer(9);
list.add(numberInt);
Integer n=(Integer) list.get(0);
System.out.println(list);

Before generics, you would write this piece of code:

With generics, this code becomes:
List<Number> list = new ArrayList<Number>();
Number numberInt = new Integer(9); list.add(numberInt);
Integer n= list.get(0);
System.out.println(list);

)1!'

 exibility'
*!$"

*##!
check for type correctness
'#!at the compile
time.

#!
are less time consuming
to #x #!"

0# !
the ambiguity is
less $ "

lesser
casts##!
$*$"

*cannot create
generic constructors.

)$$
 ##+*
*2'!
##"
Advantages

Limitations
Advanced Java / Session3 / 7 of 33
A Guide To Advanced Java – Module 6


)!#!'*#*#$ 
!*$/*

*'
class ClassName <T> {}

*'#
ClassName<specific datatype> obj = new ClassName<specific
datatype>();
Advanced Java / Session3 / 8 of 33
A Guide To Advanced Java – Module 6
!#
Advanced Java / Session3 / 9 of 33
A Guide To Advanced Java – Module 6
34 #
There are three types of wildcards used with generics.
Advanced Java / Session3 / 10 of 33
A Guide To Advanced Java – Module 6
5 #
Advanced Java / Session5 / 11 of 29
66
)0)
Click to edit Master text styles
Second level
Third level

Fourth level
Fifth level
Advanced Java / Session3 / 11 of 33
A Guide To Advanced Java – Module 6
# #
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Advanced Java / Session3 / 12 of 33
A Guide To Advanced Java – Module 6
31*

*##!($*$#
* #!'!$*"

#!$**!"4#
*+ #*!
 *

!*'!")#*'!
$ $+# "
Advanced Java / Session3 / 13 of 33
A Guide To Advanced Java – Module 6
31*

)$*#$ ##"

3#$* #!

#+ "
Advanced Java / Session5 / 14 of 29
67
)0)


'*#'"

1#!'"

 #!$*"

# "

8(!#"

8$# !#"
Advanced Java / Session5 / 15 of 29
6
)0)
.&$/
Advanced Java / Session5 / 16 of 33
6
)0)
Regular Expression
Writing a regular expression is more than a skill it's
an art.
992*%
Advanced Java / Session5 / 17 of 33
6

)0)
4#:

;<#$'"

RegEx'*!$*! ##
!#"

0#*#!$
"
Advanced Java / Session5 / 18 of 33
6=
)0)
)

0##!#)

/""".#$/!#$*!$
'

/"""#.##$/'#$(


/"""*.$/#+#*
"
String regex = "\\d+[.]?\\d*";
String data = "abc 23 gfgf 64.434.43gfdgfd";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(data);
//boolean b=m.matches();

while (m.find()) {
System.out.println(m.group());
}
String regex = "\\d+[.]?\\d*";
String data = "abc 23 gfgf 64.434.43gfdgfd";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(data);
//boolean b=m.matches();
while (m.find()) {
System.out.println(m.group());
}
Advanced Java / Session5 / 19 of 33
6>
)0)
*

1

#

?(



@*#

@+'
Advanced Java / Session5 / 20 of 33
-A
)0)

1

1B$

### ##2# *
!#"0#*([{\^-$|}])?*+.

0#  *$* ##!#$*
#.

#!# #$+#

#!#$*'*C?#$C#"
Advanced Java / Session5 / 21 of 33
-6
)0)
#
Character Classes
D$E $;!<
DF$E )*#$;<
D9B)9GE ##B)##G;<
D9D!9EE ##!##.D9!9E;<
D9BHHD'EE ';<
D9BHHDF$EE ##B'$.D9BE;$<
D9BHHDF!9EE ##B!##.D9I9BE;$<
Advanced Java / Session5 / 22 of 33

)0)
(#
Prede#ned Character Classes

" )*#;!*!*!#!<
C ).DA9>E
C8 )9.DFA9>E
C ) ##.DCCCA@C'CE
C )9 ##.DFCE
C  ) #.D9B)9GJA9>E
C4 )9 #.DFC E
Advanced Java / Session5 / 23 of 33
-K
)0)
@*#
LBoundary Matchers
LF L0#$'
LM L0#'
LC$ L) $*
LC@ L)9 $*
LC) L0#$'#
LC L0#'#!#
LCG L0#'#$'#(!'*
LCB L0#'#
Advanced Java / Session5 / 24 of 33
-7
)0)
?(

?( #'*#!$''
!#!#

0##*'I(.


*




Advanced Java / Session5 / 25 of 33
-
)0)

×