Archives: Map

Java – Synchronized HashMap Example

Synchronized HashMap Example in Java

HashMap is a non-synchronized collection class. If we need to perform thread-safe operations on it then we must need to synchronize it explicitly.
Iterator should be used in a synchronized block even if we have synchronized the HashMap explicitly.

Java – Map Iterate Example

Iterating Map / HashMap in different ways – Java Example

Java – NavigableMap Example

Java NavigableMap Example

— A NavigableMap is nothing but a SortedMap extended with navigation methods returning the closest matches for given search targets.
— A NavigableMap may be accessed and traversed in either ascending or descending key order.
— Submaps of any NavigableMap must implement the NavigableMap interface.


Descending Set : [Z, Y, X, T, B, A]
Floor Entry : B=600
First Entry : A=700
Last Key : Z
First Key : A
Original Map : {A=700, B=600, T=800, X=500, Y=900, Z=200}
Reverse Map : {Z=200, Y=900, X=500, T=800, B=600, A=700}