0% found this document useful (0 votes)
3 views2 pages

Java Collections Framework Overview

The Java Collections Framework (JCF) provides various containers for efficient storage and management of objects, including List, Set, Queue, and Map interfaces. Each interface has specific classes with unique characteristics and common use cases, such as ArrayList for frequent access, HashSet for unique elements, and HashMap for key-value pairs. Additionally, utility classes like Collections and Arrays offer static methods for common operations.

Uploaded by

Naman Nayan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java Collections Framework Overview

The Java Collections Framework (JCF) provides various containers for efficient storage and management of objects, including List, Set, Queue, and Map interfaces. Each interface has specific classes with unique characteristics and common use cases, such as ArrayList for frequent access, HashSet for unique elements, and HashMap for key-value pairs. Additionally, utility classes like Collections and Arrays offer static methods for common operations.

Uploaded by

Naman Nayan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Collections – Important Containers

Java Collections Framework (JCF) provides containers to store and manage groups of objects
efficiently. These containers are part of the package [Link].

1. List Interface (Ordered & Duplicates Allowed)


Class Description Common Use
ArrayList Dynamic array (fast random access, slow insertion/removal in middle) Frequent search/access operations
LinkedList Doubly linked list (fast insertion/removal, slower random access) Frequent add/remove operations
Vector Synchronized version of ArrayList (legacy) Multi-threaded environment
Stack LIFO (extends Vector) Stack operations (push/pop)

2. Set Interface (No Duplicates)


Class Description Common Use
HashSet Uses hash table (no order) Fast lookup, unique elements
LinkedHashSet HashSet + maintains insertion order Ordered set with unique elements
TreeSet Uses a balanced tree (sorted order) Sorted unique elements

3. Queue Interface (FIFO Structure)


Class Description Common Use
PriorityQueue Elements ordered by priority (natural/comparator) Task scheduling
ArrayDeque Double-ended queue (faster than Stack/LinkedList) Queue/stack replacement

4. Map Interface (Key–Value Pairs)


Class Description Common Use
HashMap Unordered key-value pairs Fast access by key
LinkedHashMap Maintains insertion order Ordered map
TreeMap Sorted by key (red-black tree) Sorted key-value mapping
Hashtable Synchronized version of HashMap (legacy) Multi-threaded environment
WeakHashMap Keys are weakly referenced (garbage-collected if not used elsewhere) Cache implementations

5. Utility Classes
Class Description
Collections Provides static methods like sort(), reverse(), shuffle(), min(), max()
Arrays Utility for array operations like sort(), binarySearch()
Example Code:
import [Link].*;

public class CollectionExample {


public static void main(String[] args) {
List<String> names = new ArrayList<>();
[Link]("Alice");
[Link]("Bob");
[Link]("Alice"); // duplicate allowed

Set<String> set = new HashSet<>(names);


Map<Integer, String> map = new HashMap<>();
[Link](1, "One");
[Link](2, "Two");

Queue<Integer> queue = new LinkedList<>();


[Link](10);
[Link](20);
[Link](); // removes 10

[Link]("List: " + names);


[Link]("Set: " + set);
[Link]("Map: " + map);
[Link]("Queue: " + queue);
}
}

You might also like