• Register

Map is an obj that plots keys to values, or is a group of characteristic value couples. It copies the method abstraction in math.

Note that a Map is not taken to be a factual collection, as the Map interface does not inherit the Collection interface. As a replacement for, it runs an self-governing branch in the Java Groups Framework, as revealed in the subsequent diagram:

Why maps are used:

Maps are flawlessly for key-value relationship mapping such as vocabularies. Use Maps when you need to recover and modernize basics by keys, or do lookups by keys. Some examples:

Generating a new map:

Generating a HashMap:

Constantly use interface type (Map), generics and diamond operator to state a new map. The subsequent chunk generates a HashMap:

Map<Integer, String> mapHttpErrors1 = new HashMap<>();
 mapHttpErrors1.put(200, "OK…");
mapHttpErrors1.put(303, "See an Other…");
mapHttpErrors1.put(404, "soory Not Found");
mapHttpErrors1.put(500, "Server Error");
System.out.println(mapHttpErrors1);

The Collection in Java is a framework that delivers an construction to stock and operate the collection of objs.

Java Collections we can attain all the processes that you do on a data such as examining, organization, inset, operation, and removal.

Java Collection defines a single element of obj. Java Collection agenda delivers many interfaces (1Set, 2List, 3Queue, 4Deque) and classes (1ArrayList, 2Vector, 3LinkedList, 4PriorityQueue, 5HashSet, 6LinkedHashSet, 7TreeSet).

Why map is not part of collection

Because Map has 3 collections: Keys, values and key-value pairs. It is portion of the collection framework but it doesn't fetch the java.util.Collection interface. It's a diverse subdivision of the order. If you need, you can outlook it on the similar level of the order as the Collection interface.

2,760 points
7 4