0% found this document useful (0 votes)
32 views4 pages

Reva Tech: Software Solution

The document provides an overview of the Map interface in Java, detailing its characteristics such as storing data in key-value pairs, not allowing duplicate keys, and its utility for searching, updating, or deleting elements. It describes various implementations of the Map interface, including HashMap, LinkedHashMap, TreeMap, and Hashtable, highlighting their unique features and behaviors. Code examples illustrate how to create and manipulate a HashMap in Java.

Uploaded by

Dhiraj Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views4 pages

Reva Tech: Software Solution

The document provides an overview of the Map interface in Java, detailing its characteristics such as storing data in key-value pairs, not allowing duplicate keys, and its utility for searching, updating, or deleting elements. It describes various implementations of the Map interface, including HashMap, LinkedHashMap, TreeMap, and Hashtable, highlighting their unique features and behaviors. Code examples illustrate how to create and manipulate a HashMap in Java.

Uploaded by

Dhiraj Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Reva Tech Software Solution

MAP

 WHAT IS MAP

1. Map in Java is an interface available in java.util package


2. Map interface is a part of Java Collection Framework, but it doesn’t inherit
Collection Interface.
3. It stores the data in key and value pairs.
4. Each key and value pair is known as an entry
5. It does not allow duplicate keys.
6. Each key must be associated with one value
7. A Map is useful if you have to search, update or delete elements on the basis
of a key.

Documented By Reva Tech Software Solution (7972590331)


Reva Tech Software Solution

HashMap: HashMap is the implementation of Map, but it doesn't maintain any


order.

LinkedHashMap: LinkedHashMap is the implementation of Map. It inherits


HashMap class. It maintains insertion order.

TreeMap: TreeMap is the implementation of Map and SortedMap. It maintains


ascending order.

Ex 1:
import java.util.HashMap;

import java.util.Map;

public class CreateHashMapExample {

public static void main(String[] args) {

// Creating a HashMap

Map<String, Integer> numberMapping = new HashMap<>();

// Adding key-value pairs to a HashMap

numberMapping.put("One", 1);

numberMapping.put("Two", 2);

numberMapping.put("Three", 3);

// Add a new key-value pair only if the key does not exist in the HashMap, or is
mapped to `null`

numberMapping.putIfAbsent("Four", 4);

System.out.println(numberMapping);

Documented By Reva Tech Software Solution (7972590331)


Reva Tech Software Solution

HashMap:
 A HashMap contains values based on the key.
 It contains only unique elements.
 It may have one null key and multiple null values.
 It maintains no order

LinkedHashMap: LinkedHashMap offers 0(1) lookup and insertion. Keys are


ordered by their insertion order. It is implemented by doubly-linked buckets.

 A LinkedHashMap contains values based on the key.


 It contains only unique elements.
 It may have one null key and multiple null values.
 It is same as HashMap instead maintains insertion order.

TreeMap:
 A TreeMap contains values based on the key. It implements the NavigableMap
interface and extends AbstractMap class.
 It contains only unique elements.
 It cannot have null key but can have multiple null values.
 It is same as HashMap instead maintains ascending order(Sorted using the
natural order of its key).

Hashtable:
 A Hashtable is an array of list. Each list is known as a bucket. The position of
bucket is identified by calling the hashcode() method. A Hashtable contains
values based on the key.
 It contains only unique elements.
 It may have not have any null key or value.
 It is synchronized.
 It is a legacy class.

Documented By Reva Tech Software Solution (7972590331)


Reva Tech Software Solution

Documented By Reva Tech Software Solution (7972590331)

You might also like