Junior — Middle
Is the Map data structure part of the collections in Java?
sobes.tech AI
Answer from AI
In Java, the Map interface is not part of the hierarchy of collections inherited from the Collection interface. Although Map is related to collections, it represents a separate data structure for storing key-value pairs. The main collections in Java are lists (List), sets (Set), and queues (Queue), which inherit from Collection.
Example of using Map:
Map<String, Integer> map = new HashMap<>();
map.put("apple", 3);
map.put("banana", 5);
System.out.println(map.get("apple")); // Will output 3