WeakHashMap in Java

What is WeakHashMap WeakHashMap is based on Hash table implementation of the Map interface but with weak keys. An entry in a WeakHashMap will automatically be removed when its key is no longer in ordinary use. When a key has been discarded due to weakness characteristics of keys its entry is effectively removed from the map, so this class behaves somewhat differently from other Map implementations. Like HashMap both null values and the null key are supported.WeakHashMap has performance characteristics similar to the HashMap and has the same efficiency parameters…

Continue

TreeMap in Java

What is TreeMap? It is a Red-Black tree based NavigableMap implementation. Like HashMap it contains only unique elements. Unlike HashMap it cannot have null key but like HashMap it can have multiple null values. The map is sorted according to the natural ordering (ascending order) of its keys, or by a Comparator provided at map creation time, depending on which constructor is used.

Continue

LinkedHashMap in Java

What is LinkedHashMap A LinkedHashMap like HashMap is a simple yet powerful way to store and get data. Unlike HashMap, LinkedHashMap is based on HashTable and Linked list implementation of the Map interface and stores items as key/value pairs. Like HashMap, LinkedHashMap permits only unique keys. It also permits only one null key (whereas HashTable does not allow any null key) but may have more than one null values. Unlike HashMap, it does make garuntee of the order of the elements stored in it. All operations happen in LinkedHashMap(in HashMap…

Continue

Iterator Design Pattern in Java

Iterator pattern falls under behavioral design pattern. Iterator pattern is very commonly used design pattern in Java. This pattern is used to iterate through a collection of objects without exposing its underlying representation. It is used to access the elements of an aggregate object sequentially. For example, Java’s collections like ArrayList and HashMap have implemented the iterator pattern.

Continue