View RSS Feed

Algorithm and Data Structure

Java Map Implementations

Rate this Entry
by , 02-19-2012 at 08:21 AM (1023 Views)
Map can’t 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.

• java.util.HashMap
• java.util.Hashtable
• java.util.EnumMap
• java.util.IdentityHashMap
• java.util.LinkedHashMap
• java.util.Properties
• java.util.TreeMap
• java.util.WeakHashMap

Map implementations which are commonly used are:

• TreeMap
• HashMap

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 creation
Map mapA = new HashMap();
Map mapB = new TreeMap();

Submit "Java Map Implementations" to Facebook Submit "Java Map Implementations" to Digg Submit "Java Map Implementations" to Submit "Java Map Implementations" to StumbleUpon Submit "Java Map Implementations" to Google