Java Map Implementations
by, 02-19-2012 at 07:21 AM (990 Views)
Map cant be instantiated as it is an interface. For creation of the Map interface instance, concrete implementation is required. Map interface has these concrete implementations which are present in Collection API.
Map implementations which are commonly used are:
Such approaches could be differentiated based on implementations. Element order is the basic difference, when iteration is performed and also the time duration it would be taking for insertion or access of the Set elements.
Base of the HashMap is key value pair. A key is mapped to its value. Elements stored are not supported or guaranteed by it.
Base of the TreeMap is key value pair. The order in which values get iterated are guaranteed by it.
How a Map instance is created is explained by these examples:
Java Code: This is the code to explain map creationMap mapA = new HashMap(); Map mapB = new TreeMap();