Java Collection Framework
Java Collection Framework
The Java Collection Framework provides a set of classes and interfaces for handling and manipulating collections of objects. This document details each
major collection type, their methods, advantages, limitations, and traversal techniques.
Name Methods Description Example How to Access Advantage Limitation Working How to
Traverse
List add(), remove(), Ordered collection List<String> list = ArrayList<>, Allows Slower Uses an indexed for loop,
get(), set(), that allows new LinkedList<> duplicate search in structure in forEach(),
indexOf(), size(), duplicates. ArrayList<>(); values and LinkedList ArrayList, nodes in Iterator,
contains(), Implementations: list.add("Apple"); maintains than LinkedList ListIterator
isEmpty(), sort() ArrayList, order ArrayList
LinkedList, Vector
Set add(), remove(), Unordered Set<Integer> set = HashSet<>, Ensures No direct Uses hashing forEach(),
contains(), size(), collection, no new HashSet<>(); TreeSet<>, uniqueness indexing; (HashSet), tree Iterator
isEmpty(), duplicates. set.add(10); LinkedHashSet<> slower structure (TreeSet),
iterator() Implementations: lookup or linked list
HashSet, TreeSet, (LinkedHashSet)
LinkedHashSet
Map put(), get(), Key-value pair Map<String, HashMap<>, Fast lookup No direct Uses hashing forEach(),
remove(), collection. Integer> map = TreeMap<>, using keys indexing (HashMap), tree Iterator (via
containsKey(), Implementations: new LinkedHashMap<> structure entrySet())
containsValue(), HashMap, HashMap<>(); (TreeMap), or
keySet(), TreeMap, map.put("A", 1); linked list
entrySet() LinkedHashMap, (LinkedHashMap)
Hashtable
Queue offer(), poll(), Follows FIFO Queue<Integer> q LinkedList<>, Ensures Limited Uses linked Iterator,
peek(), remove(), (First-In-First-Out) = new PriorityQueue<> ordered access to structure in forEach(),
element() principle. LinkedList<>(); processing elements LinkedList, heap in poll()
Implementations: q.offer(10); PriorityQueue (dequeue
PriorityQueue, mechanism)
LinkedList
Stack push(), pop(), LIFO (Last-In- Stack<Integer> Stack<> (Subclass Useful for Slower than Uses a dynamic Iterator,
peek(), First-Out) stack = new of Vector<>) recursion, ArrayDeque array (inherits from forEach(),
isEmpty(), structure, a Stack<>(); undo-redo Vector) pop() (LIFO
search() subclass of Vector stack.push(5); mechanism)