0% found this document useful (0 votes)
5 views1 page

Java Collections Comparison

The document provides a comparison chart of the Java Collection Framework, detailing features of various types such as List, Set, Queue/Deque, and Map. It highlights aspects like insertion order, allowance of heterogeneous elements, null values, duplicates, default capacity, size increase behavior, synchronization, and use cases for each collection type. This chart serves as a quick reference for understanding the differences and appropriate applications of each collection type in Java.
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)
5 views1 page

Java Collections Comparison

The document provides a comparison chart of the Java Collection Framework, detailing features of various types such as List, Set, Queue/Deque, and Map. It highlights aspects like insertion order, allowance of heterogeneous elements, null values, duplicates, default capacity, size increase behavior, synchronization, and use cases for each collection type. This chart serves as a quick reference for understanding the differences and appropriate applications of each collection type in Java.
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 Collection Framework - Comparison Chart

Feature / Type List (ArrayList, LinkedList, Vector)Set (HashSet, LinkedHashSet, TreeSet)


Queue / Deque (PriorityQueue, LinkedList,
Map (HashMap,
ArrayDeque)
LinkedHashMap, Tr

Insertion Order ■ Maintained (ArrayList, LinkedList,


■ HashSet
Vector) (No order) ■ LinkedList/ArrayDeque maintain■order
HashMap (No order)
■ LinkedHashSet (Insertion order)■ PriorityQueue (Sorted by priority)
■ LinkedHashMap (Insertion order)
■ TreeSet (Sorted order) ■ TreeMap (Sorted order)

■ Allowed (except TreeSet with non-comparable)


Heterogeneous Elements■ Allowed (except when using generics) ■ Allowed (except PriorityQueue needing
■ Allowed
Comparable)
(Key & Value can be diffe

Null Values ■ Multiple nulls allowed ■ Only one null allowed (HashSet/LinkedHashSet)
■ LinkedList allows nulls ■ One null key (HashMap, LinkedHa
■ TreeSet doesn’t allow null ■ PriorityQueue & ArrayDeque don’t
■ Multiple
allow null
null values
■ TreeMap: no null key but null valu
■ Hashtable: no null key/value

Duplicates ■ Allowed ■ Not allowed ■ Allowed ■ Keys not allowed, ■ Values can d

Default Capacity ArrayList: 10 HashSet/LinkedHashSet: 16 PriorityQueue: 11 HashMap: 16 (0.75 load)


Vector: 10 TreeSet: N/A ArrayDeque: 16 LinkedHashMap: 16
LinkedList: N/A LinkedList: N/A TreeMap: N/A
Hashtable: 11

Size Increases By ArrayList → 1.5x HashSet/LinkedHashSet → doubles


PriorityQueue/ArrayDeque → 2x HashMap/LinkedHashMap → 2x
Vector → 2x TreeSet: N/A Hashtable → 2x+1

Synchronized? ■ ArrayList, LinkedList ■ Not synchronized ■ Not synchronized (ConcurrentLinkedQueue


■ HashMap/LinkedHashMap/TreeM
exists)
■ Vector (sync) ■ Hashtable
■ ConcurrentHashMap

When to Use? For ordered, index-based CRUD. For unique elements. For FIFO/LIFO/priority tasks. For key-value pairs.
ArrayList → fast access. HashSet → fast lookup. Queue → task scheduling. HashMap → fast lookup.
LinkedList → frequent insert/delete.
LinkedHashSet → maintain [Link] → double-ended ops. LinkedHashMap → maintain order.
Vector → legacy sync. TreeSet → sorted data. PriorityQueue → scheduling. TreeMap → sorted keys.
Hashtable/ConcurrentHashMap → th

You might also like