In my previous post we have learnt How to Sort HashMap in Java by Keys, in this article we will learn to sort HashMap values. We will be using the below three approaches. Implementing the Comparator Interface along with TreeMap Collection Implementing a separate class implementing Comparator Interface Using Collections.sort() method … [Read more...]
How to Sort HashMap in Java by Keys
We all know that HashMap will not save key-value pairs in any sort of order neither preserve the insertion order. In this tutorial we will learn how to sort a HashMap based on Keys. We will be using two approaches. TreeMap Collection class (Which has in-built support for sorting the elements using Comparable and Comparator Interface) Implementing the Comparator … [Read more...]
Java TreeMap values() Method Example
The values() method of java.util.TreeMap class returns a Collection view of the values contained in this map. The collection's iterator returns the values in ascending order of the corresponding keys. … [Read more...]
Java TreeMap floorKey() Method Example
The floorEntry() method of java.util.TreeMap class returns a key-value mapping associated with the greatest key less than or equal to the given key, or null if there is no such key. whereas floorKey() method returns the greatest key less than or equal to the given key, or null if there is no such key. … [Read more...]
Java TreeMap ceilingEntry(K key) Example
The ceilingEntry(K key) method of java.util.TreeMap class returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key. … [Read more...]