//The Map interface maps unique keys to values. A key is an object that you use to retrieve a value at a later date.
Given a key and a value, you can store the value in a Map object. After the value is stored, you can retrieve it by using its key.
Several methods throw a NoSuchElementException when no items exist in the invoking map.
A ClassCastException is thrown when an object is incompatible with the elements in a map.
A NullPointerException is thrown if an attempt is made to use a nullobjectandnull is not allowed in the map.
An UnsupportedOperationException is thrown when an attempt is made to change an unmodifiable map.
Example of List, Set, Map
import java.util.*; // All the classes and interfaces are part of the util packagepublicclassCollectionsDemo {
publicstaticvoidmain(String[] args) {
// ArrayList
List a1 =newArrayList();
a1.add("Zara");
a1.add("Mahnaz");
a1.add("Ayan");
System.out.println(" ArrayList Elements");
System.out.print("\t"+ a1);
// LinkedList
List l1 =newLinkedList();
l1.add("Zara");
l1.add("Mahnaz");
l1.add("Ayan");
System.out.println();
System.out.println(" LinkedList Elements");
System.out.print("\t"+ l1);
// HashSet
Set s1 =newHashSet();
s1.add("Zara");
s1.add("Mahnaz");
s1.add("Ayan");
System.out.println();
System.out.println(" Set Elements");
System.out.print("\t"+ s1);
// HashMap
Map m1 =newHashMap();
m1.put("Zara", "8");
m1.put("Mahnaz", "31");
m1.put("Ayan", "12");
m1.put("Daisy", "14");
System.out.println();
System.out.println(" Map Elements");
System.out.print("\t"+ m1);
}
}
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email