Java.Collections.What is a “collection”?

A collection in Java refers to objects that implement the Collection interface, which is part of the Java Collections Framework (JCF).

2. What Implements Collection?

The Collection interface is implemented by these key interfaces:

  • List<E>ArrayList, LinkedList, etc.
  • Set<E>HashSet, TreeSet, etc.
  • Queue<E>PriorityQueue, LinkedList (as a queue).

Hierarchy Diagram

            Collection (interface)
                │
        ┌──────┴──────┐
       List         Set        Queue
        │            │           │
   ArrayList      HashSet   PriorityQueue
   LinkedList     TreeSet   LinkedList (Queue)

3. Why Map<K, V> is Not a Collection

  • Map<K, V> does not implement Collection because it works with key-value pairs, not a group of individual elements.
  • It belongs to the Java Collections Framework, but it is a separate interface.

Hierarchy for Map

            Map (interface)
                │
        ┌──────┴──────┐
     HashMap       TreeMap
This entry was posted in Без рубрики. Bookmark the permalink.