•
!"
•
List#!$!
"!!ArrayList
LinkedList
•
Set!"!!
HashSetLinkedSetLinkHashSet"
•
Queue%%&"&'!!PriorityQueue"
•
Iterator!## #(
"
•
)Map'Entry"#*'
keyvalue"' #+* ",*
$"
•
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
34 #
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
31*
•
*##!($*$#
* #!'!$*"
•
#!$**!"4#
*+ #*!
*
•
!*'!")#*'!
$ $+# "
Advanced Java / Session3 / 13 of 33
A Guide To Advanced Java – Module 6
31*
•
)$*#$ ##"
•
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.
992*%
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
•
1B$
•
### ##2# *
!#"0#*([{\^-$|}])?*+.
•
0# *$* ##!#$*
#.
–
#!# #$+#
–
#!#$*'*C?#$C#"
Advanced Java / Session5 / 21 of 33
-6
)0)
#
Character Classes
D$E $;!<
DF$E )*#$;<
D9B)9GE ##B)##G;<
D9D!9EE ##!##.D9!9E;<
D9BHHD'EE ';<
D9BHHDF$EE ##B'$.D9BE;$<
D9BHHDF!9EE ##B!##.D9I9BE;$<
Advanced Java / Session5 / 22 of 33
)0)
(#
Prede#ned Character Classes
" )*#;!*!*!#!<
C ).DA9>E
C8 )9.DFA9>E
C ) ##.DCCCA@C'CE
C )9 ##.DFCE
C ) #.D9B)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)