@@ -57,35 +57,50 @@ public static void main(String[] args) {
57
57
iList .add (40 );
58
58
iList .add (30 );
59
59
60
+ //Binary Search in List Collection
60
61
int index = Collections .binarySearch (iList , 190 );
61
- System .out .println ("Binary Search index is : " +index );
62
+ System .out .println ("Binary Search of 190 index is : " +index );
62
63
64
+ //Copy one list to another list
65
+ //It does not create new list
66
+ //It copies the values into the new list indexs
63
67
ArrayList <Integer > newList = new ArrayList <>();
64
68
newList .add (11 );
65
69
newList .add (12 );
66
70
newList .add (13 );
67
71
newList .add (14 );
68
72
newList .add (15 );
69
- Collections .copy (newList , iList ); //newList should have the same size as src list
70
- System .out .println ("Copied List : " +newList );
71
-
73
+ //newList should have minimum size as iList
74
+ Collections .copy (newList , iList );
75
+ System .out .println ("Copying the list from another list : " +newList );
76
+
77
+ //Creating Immutable Collection
72
78
Set <String > emptySet = Collections .emptySet ();
79
+ List <String > emptyList = Collections .emptyList ();
80
+ Map <String , String > emptyMap = Collections .emptyMap ();
81
+ System .out .println ("Creating immutable collection (list, set, map)" );
73
82
System .out .println ("Empty Set : " +emptySet .size ());
74
83
//emptySet.add("Try"); //not allowed its immutable
75
84
85
+ //replacing all the elements with the new value
76
86
Collections .replaceAll (iList , 10 , 100 );
87
+ System .out .println ("Replacing all the 10 in the list with 100 :" );
77
88
System .out .println (iList );
78
89
90
+ //shuffling the list
79
91
Collections .shuffle (iList );
92
+ System .out .println ("Shuffle the Elements in the List : " );
80
93
System .out .println (iList );
81
94
95
+ //Creating singleton Collection Set, List, Map
82
96
Set <String > singletonSet = Collections .singleton ("Java" );
97
+ System .out .println ("Creating singleton Collection : " );
83
98
System .out .println (singletonSet );
84
99
// singletonSet.add("Hello"); //not supported its immutable
85
100
101
+ //Creating synchronized Collection List, Set, Map
86
102
Map <Integer , String > map = new HashMap <>();
87
103
map = Collections .synchronizedMap (map );
88
-
89
-
104
+ System .out .println ("Creating synchronizing Collection : " );
90
105
}
91
- }
106
+ }
0 commit comments