Difference Between Collection Interfaces and Classes in Java
Interface /
Class |
Description |
Type |
Allows
Duplicates? |
Allows Null
Values? |
Ordering
Guaranteed? |
Thread-safe? |
Collection |
The root interface of all
collection classes. |
Interface |
Yes |
Yes |
No |
No |
List |
A collection that allows duplicate
elements and maintains their order. |
Interface |
Yes |
Yes |
Yes |
No |
Set |
A collection that does not allow
duplicate elements. |
Interface |
No |
Yes |
No |
No |
SortedSet |
A Set that maintains its elements
in ascending order. |
Interface |
No |
Yes |
Yes |
No |
Navigable Set |
A SortedSet with navigation
methods. |
Interface |
No |
Yes |
Yes |
No |
Queue |
A collection for holding elements
that are waiting to be processed. |
Interface |
Yes |
Yes |
Yes |
No |
Deque |
A Queue that supports operations at
both ends. |
Interface |
Yes |
Yes |
Yes |
No |
Map |
An object that maps keys to values. |
Interface |
No (keys are unique) |
Yes (values can be duplicated) |
No |
No |
Sorted Map |
A Map that maintains its entries in
ascending order of the keys. |
Interface |
No (keys are unique) |
Yes (values can be duplicated) |
Yes |
No |
Navigable Map |
A Sorted Map with navigation
methods. |
Interface |
No (keys are unique) |
Yes (values can be duplicated) |
Yes |
No |
ArrayList |
An implementation of the List
interface using an array. |
Class |
Yes |
Yes |
Yes |
No |
LinkedList |
An implementation of the List
interface using a doubly-linked list. |
Class |
Yes |
Yes |
Yes |
No |
HashSet |
An implementation of the Set
interface using a hash table. |
Class |
No |
Yes |
No |
No |
Linked Hash Set |
An implementation of the Set
interface using a hash table with a linked list. |
Class |
No |
Yes |
Yes |
No |
Tree Set |
An implementation of the SortedSet
interface using a tree. |
Class |
No |
Yes |
Yes |
No |
Array Deque |
An implementation of the Deque
interface using an array. |
Class |
Yes |
Yes |
Yes |
No |
Priority Queue |
An implementation of the Queue
interface using a priority heap. |
Class |
Yes |
Yes |
Yes |
No |
HashMap |
An implementation of the Map
interface using a hash table. |
Class |
No (keys are unique) |
Yes (values can be duplicated) |
No |
No |
Linked HashMap |
An implementation of the Map
interface using a hash table with a linked list. |
Class |
No (keys are unique) |
Yes (values can be duplicated) |
Yes |
No |
Tree Map |
An implementation of the Sorted Map
interface using a tree. |
Class |
No (keys are unique) |
Yes (values can be duplicated) |
Yes |
No |
0 Comments