Java.Collections.Name the main JCF interfaces and their implementations.

1. Collection Interface (Root Interface)

The Collection<E> interface is the root of the framework, but it doesn’t have direct implementations. Instead, it has three key subinterfaces:

A. List Interface (List<E>) – Ordered, allows duplicates

ImplementationDescription
ArrayList<E>Resizable array (fast random access, slower insertions/removals)
LinkedList<E>Doubly linked list (fast insertions/removals, slow random access)
Vector<E>Synchronized version of ArrayList (rarely used today)
Stack<E>LIFO stack (extends Vector)

B. Set Interface (Set<E>) – No duplicates, unordered

ImplementationDescription
HashSet<E>Uses a HashMap internally (fast, no order)
LinkedHashSet<E>Preserves insertion order (slightly slower than HashSet)
TreeSet<E>Stores elements in sorted order (implemented using TreeMap)

C. Queue Interface (Queue<E>) – Follows FIFO (First-In-First-Out)

ImplementationDescription
PriorityQueue<E>Elements are ordered based on natural ordering or a comparator
LinkedList<E>Can be used as a queue (FIFO) or a deque (double-ended queue)

Specialized Queue:

InterfaceImplementationDescription
Deque<E> (Double-ended queue)ArrayDeque<E>More efficient than Stack, allows adding/removing from both ends

2. Map Interface (Map<K, V>) – Key-Value pairs, No duplicate keys

ImplementationDescription
HashMap<K, V>Fast access, unordered keys (most commonly used Map)
LinkedHashMap<K, V>Maintains insertion order
TreeMap<K, V>Stores keys in sorted order
Hashtable<K, V>Thread-safe version of HashMap (rarely used today)
ConcurrentHashMap<K, V>Thread-safe, high-performance alternative to Hashtable

Hierarchy Summary

Collection (interface)
    ├── List<E>
    │   ├── ArrayList<E>
    │   ├── LinkedList<E>
    │   ├── Vector<E>
    │   ├── Stack<E>
    │
    ├── Set<E>
    │   ├── HashSet<E>
    │   ├── LinkedHashSet<E>
    │   ├── TreeSet<E>
    │
    ├── Queue<E>
    │   ├── PriorityQueue<E>
    │   ├── LinkedList<E> (Queue)
    │
    ├── Deque<E>
        ├── ArrayDeque<E>
    
Map<K, V> (interface)
    ├── HashMap<K, V>
    ├── LinkedHashMap<K, V>
    ├── TreeMap<K, V>
    ├── Hashtable<K, V>
    ├── ConcurrentHashMap<K, V>

Key Takeaways

  • Collection interface is the root interface of List, Set, and Queue.
  • Map is NOT a Collection, but is part of the Java Collections Framework.
  • Use Cases:
    • ArrayList → Fast random access, dynamic size.
    • LinkedList → Fast insertions/removals, slow access.
    • HashSet → Unique elements, fast operations.
    • TreeSet → Sorted elements.
    • HashMap → Fast key-value lookups.
This entry was posted in Без рубрики. Bookmark the permalink.