Sobes.tech
Junior — Middle

Can you list classes that implement the Map interface or inherit from it?

sobes.tech AI

Answer from AI

In Java, the following main classes from the standard library implement the Map interface:

  • HashMap — implements a hash table, provides fast access by key.
  • TreeMap — implements a red-black tree, stores keys in sorted order.
  • LinkedHashMap — extends HashMap, maintains insertion order.
  • Hashtable — an outdated class, synchronized hash table.
  • ConcurrentHashMap — thread-safe implementation of a hash table for concurrent access.

Example of using HashMap:

Map<String, Integer> map = new HashMap<>();
map.put("apple", 3);
map.put("banana", 5);
System.out.println(map.get("apple")); // 3
Can you list classes that implement the Map interface… - sobes.tech