Home » Core Java » Java Collection API -Part 2 (Map)

Java Collection API -Part 2 (Map)

In continuation of first part of introduction to Java Collection API Part 1, now we would be covering the other part and that is Map api. MAP is designed to store Key-Value pair combination as we know. Some distinct features of MAP are

  • Key can not be repeated
  • Key can be mapped to only one value
  • It depicts mathematical function F(x) -> y , where x represents key and y is the value
  • Basic operations provided by map : get, put , containsKey, containsValue , empty , size
  • Map provides collections views to iterate over the values it holds
    • ketSet      : Set of keys
    • value        : Collection os values, it is not a set as multiple keys can point to same values
    • entrySet  : Map internally contains the set of key-value pair which is represented my inner interface Map.Entry
  • These collections views are good for iteration , modification , removal but CAN NOT BE USED For ADDITION
  • Java API has provided three implementation of MAP interface: HashMap, HashTable, LinkedHashMap
  • MAP also has another sub interface SortedMap which is implemented  by TreeMap
JAVA MAP Api

JAVA MAP Api

1: HashMap: HashMap is most basic implementation of MAP interface

2: HashTable : Similar to HashMap
-Thread safe and synchronized

3: LinkedHashMap : Values are placed internally as likened list
-Ordered

4: TreeSet : Values are placed in sorted manner. Natural sort of Comparable/Comparator logic is used. It is the similar collection as TreeSet but here Key’s are compared and sorted while putting values in MAP.

Advertisements

2 Comments

  1. […] Rehashing in Java HashMap and Race condition Java Collection API -Part 2 (Map) → Oct 16 […]

  2. Rohit says:

    this blog offers great information and interesting to read. i enjoyed reading both collection blogs.
    good job !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: