Skip to content

Commit 7825faf

Browse files
committed
Core Java
1 parent 7516a04 commit 7825faf

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

Collections/src/com/cdac/collections/collectionsutils/CollectionsDemo.java

+22-7
Original file line numberDiff line numberDiff line change
@@ -57,35 +57,50 @@ public static void main(String[] args) {
5757
iList.add(40);
5858
iList.add(30);
5959

60+
//Binary Search in List Collection
6061
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);
6263

64+
//Copy one list to another list
65+
//It does not create new list
66+
//It copies the values into the new list indexs
6367
ArrayList<Integer> newList = new ArrayList<>();
6468
newList.add(11);
6569
newList.add(12);
6670
newList.add(13);
6771
newList.add(14);
6872
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
7278
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)");
7382
System.out.println("Empty Set : "+emptySet.size());
7483
//emptySet.add("Try"); //not allowed its immutable
7584

85+
//replacing all the elements with the new value
7686
Collections.replaceAll(iList, 10, 100);
87+
System.out.println("Replacing all the 10 in the list with 100 :");
7788
System.out.println(iList);
7889

90+
//shuffling the list
7991
Collections.shuffle(iList);
92+
System.out.println("Shuffle the Elements in the List : ");
8093
System.out.println(iList);
8194

95+
//Creating singleton Collection Set, List, Map
8296
Set<String> singletonSet = Collections.singleton("Java");
97+
System.out.println("Creating singleton Collection : ");
8398
System.out.println(singletonSet);
8499
// singletonSet.add("Hello"); //not supported its immutable
85100

101+
//Creating synchronized Collection List, Set, Map
86102
Map<Integer, String> map = new HashMap<>();
87103
map = Collections.synchronizedMap(map);
88-
89-
104+
System.out.println("Creating synchronizing Collection : ");
90105
}
91-
}
106+
}

Generics/src/com/cdac/generics/NumberDatabaseMain.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void main(String[] args) {
1717
longDatabase.set(1200000000L);
1818
System.out.println("Long from database : "+longDatabase.get());
1919

20-
//NumberDatabase<String> stringDatabase = new NumberDatabase<>();
20+
// NumberDatabase<String> stringDatabase = new NumberDatabase<>();
2121
//the above code will throw error
2222
//String class is not derived from Number class
2323

Generics/src/com/cdac/generics/StringDB.java

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static void main(String[] args) {
1212

1313
Database<Date> date = new Database<>();
1414
date.set(new Date());
15+
Date dd = date.get();
1516
// String abc = (String)date.get(); // not ok
1617
}
1718

0 commit comments

Comments
 (0)