1
2
3
4
5
6
The entire listing of interfaces, implementation classes and algorithm classes are present in java.util package except Comparable interface. Map does not extend java.util.Collection. All implementation classes marked as (Legacy) contains synchronized methods. It does not support concurrent access.
7
Refer: http://download.oracle.com/javase/1.4.2/docs/api/java/util/Collection.html for description of other methods of Collection interface.
8
9
Performance of sorting and searching operations with collections of size n is measured using Big-O notation. The notation describes the complexity of the algorithm in relation to the maximum time in which an algorithm operates, for large values of n. For instance, if you iterate through an entire collection to find an element, the Big-O notation is referred to as O(n), meaning that as n increases, time to find an element in a collection of size n increases linearly. This demonstrates that Big-O notation assumes worst case performance. It is always possible that performance is quicker.
For more information on Big O notation refer: http://en.wikipedia.org/wiki/Big_O_notation
10
LinkedList also implements Deque<E>, Queue<E> from Java version 1.6 onwards. The Queue and Deque interface provides first-in-first-out queue operations for add, poll.
11
For information on other methods Refer: http://download.oracle.com/javase/6/docs/api/java/util/LinkedList.html
12
13
14
With Generics the collections becomes type-safe. If the code compiles the programmer will not get any class-cast exception at runtime.
15
Note: Try writing a generic code that can work on many types of containers like Set and List.
16
17
18
19
20
The code of compareTo() is written assuming that the employeeId is unique. If the comparison is based on fields which are not unique: if the difference of two values result in the value 0, then return the difference of other fields. Example: public int compareTo(Employee employee) {
int difference = this.getFirstName().compareTo(employee.getFirstName()); if( difference == 0 ) { difference = Double.compare(this.getSalary(), employee.getSalary()); } } return difference;
21
22
23
Inner classes can access all the members of outer class even if the outer class members are private. Inner classes can be static or non-static.
24
25
26
Whenever hashCode() returns same INTEGER, equals() method is used to check objects equality.
27
28
Refer:http://www.cs.auckland.ac.nz/~jmor159/PLDS210/red_black.html for information on RedBlack tree.
29
30
31
32
33
Read more about Load Factor and Rehashing :http://goo.gl/uumsm
34
35
To specify the load factor create instance as new HashMap(0.75f); i.e. if 75% of buckets are filled bucket size increases and rehashing takes place.
36
Object get(Object key) method of Map returns “null” if key is not found.
37
38
Refer : 1) http://javahowto.blogspot.com/2006/06/4-ways-to-traverse-map.html 2) http://stackoverflow.com/questions/3870064/performance-considerationsfor-keyset-and-entryset-of-map 3) http://ulibgcj.sourceforge.net/javadoc/java/util/HashMap.html
39
40
41
42
43
44
45
Refer: http://goo.gl/Y3Ybq for information on Enum type.
46
47
48
Similarly complete this flow chart for choosing a Map.
49
50
51
52
53
54
55
56
57