Please enable JavaScript.
Coggle requires JavaScript to display documents.
Generics and Collections (Array and ArrayList (an ArrayList can`t contain…
Generics and Collections
-
Sorting and Searching
Sorting
int [] array = {6, 3, 7,9}; Arrays.sort(array);
List<Integer> list = Arrays.asList(4,3,5,7); Collections.sort(list);
Search
sout(Collections.binarySearch(list, 5)); ---> 2 (index)
sout(Arrays.binarySearch(array, 6)); ---> 0 (index)
sout(Arrays.binarySearch(array, 10)); -> -4 (one less then the negative index of the place in sorted array where it would need to be inserted)
-
The Diamond operator <>
Before it was introduced in Java 5, while writing List names = new ArrayList(); programmers hoped that only String would be added to the names list. There were no way to enforce it
-
non-generic list can contain objects of any type; However, adding to Generic list object of illegal type will not compile
-