Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, 4 October 2016

What is Map Interface in Java ?

This blog is all about to learn Core Java Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.


Here we learn what is Map Interface In Java.
Interface Map<K,V>

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values

Known Subinterfaces:

Known Implementing Classes:

Map interface belongs to java.util.* package .Map interface maps keys to values. A map cannot contain duplicate keys; each key can map to atleast one value.
Map interface takes the place of the Dictionary class, which was a totally abstract class rather than an interface.
Some map implementations, like the TreeMap class, guarantees as to their order; others, like the HashMap class do not guarantee their order.
Map interface is a member of the Java Collections Framework.

Map Interface Basic Operations
The basic operations of Map are put, get, containsKey, containsValue, size, and isEmpty.

Example Of Map interface :-

import java.util.HashMap;
import java.util.Map;

public class MapInterfaceExample {

public static void main(String[] args) {
String[] arr = {"This","is","a","map","interface","example"};
Map<String, Integer> map = new HashMap<>();
for(String str : arr){
map.put(str, 1);
}
System.out.println("MAP : "+map);
System.out.println("MAP GET() : "+map.get("a"));
System.out.println("MAP SIZE() : "+map.size());
System.out.println("MAP IS EMPTY() : "+map.isEmpty());
System.out.println("MAP CONTAINS KEY (is) : "+map.containsKey("is"));
System.out.println("MAP CONTAINS VALUE (1) : "+map.containsValue(1));
}

}

Program Output :-

MAP : {a=1, This=1, is=1, interface=1, map=1, example=1}
MAP GET() : 1
MAP SIZE() : 6
MAP IS EMPTY() : false
MAP CONTAINS KEY (is) : true
MAP CONTAINS VALUE (1) : true



Share this Blog with yours Friends !!

No comments:

Post a Comment