Archives: HashMap

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 – Convert Map to JSON

Convert Map to JSON in Java

Output:

json = {“WHITE”:”#FFFFFF”,”BLUE”:”#0000FF”,”YELLOW”:”#FFFF00″,”GREEN”:”#008000″,”BLACK”:”#000000″,”RED”:”#FF0000″}
map.get = #FFFFFF
map.get = #0000FF
map.get = #FFFF00
map.get = #008000
map.get = #000000
map.get = #FF0000