Java TreeMap with Example

Java TreeMap is an ordered Java Map. It has the special property that it keeps the entries sorted (in ascending order) either by the natural order of its keys or using the Comparator provided to constructor. TreeMap uses a balanced tree internally to keep the keys ordered. Oracle’s JDK implementation uses Red-Black  Trees (a kind of balanced binary tree). Because TreeMap uses balanced trees,… Continue reading Java TreeMap with Example

Java HashMap with Example

Java HashMap is the most popular concrete implementation of Java Map. The distinguishing feature of HashMap is that it is based on the celebrated hashtable data structure. Like any other Java Map, a HashMap maintains associations between keys and values. A HashMap is an unordered collection, meaning you should not use HashMap if your program requires iteration or retrieval in a predictable order. Nevertheless, a HashMap is extremely efficient… Continue reading Java HashMap with Example