Collection is a framework that provides an architecture to store and manipulate a group of objects. The Collection interface is part of the Java Collections Framework, which provides a unified architecture for representing and manipulating collections. It includes interfaces, implementations, and algorithms to handle data manipulation tasks such as searching, sorting, insertion, deletion, etc.
The main interfaces in the Java Collections Framework include:
- Collection - The root interface for the collection hierarchy.
- List - An ordered collection (also known as a sequence) that can contain duplicate elements. Example implementations include
ArrayList,LinkedList. - Set - A collection that cannot contain duplicate elements. Example implementations include
HashSet,LinkedHashSet,TreeSet. - Queue - A collection used to hold multiple elements prior to processing. Example implementations include
PriorityQueue,LinkedList(as a Queue). - Map - An object that maps keys to values, with no duplicate keys allowed. Example implementations include
HashMap,TreeMap,LinkedHashMap.
classDiagram Iterable <|-- Collection Collection <|-- List Collection <|-- Set Collection <|-- Queue class Iterable { <<interface>> +iterator() } class Collection { <<interface>> +add(Object) +remove(Object) +size() } class List { <<interface>> // Ordered collection } class Set { <<interface>> // No duplicates } class Queue { <<interface>> // FIFO collection } class Deque { <<interface>> // Double-ended queue } class Map { <<interface>> // Key-value pairs } class SortedSet { <<interface>> // Ascending order } class NavigableSet { <<interface>> // Navigation methods } class SortedMap { <<interface>> // Ascending key order } class NavigableMap { <<interface>> // Navigation based on keys } List <|.. ArrayList List <|.. LinkedList List <|.. Vector List <|.. Stack Set <|.. HashSet Set <|.. LinkedHashSet Set <|.. TreeSet Queue <|.. PriorityQueue Queue <|.. LinkedList Deque <|-- Queue Deque <|.. ArrayDeque Deque <|.. LinkedList Map <|.. HashMap Map <|.. LinkedHashMap Map <|.. TreeMap SortedSet <|-- Set SortedSet <|.. TreeSet NavigableSet <|-- SortedSet NavigableSet <|.. TreeSet SortedMap <|-- Map SortedMap <|.. TreeMap NavigableMap <|-- SortedMap NavigableMap <|.. TreeMap

Iterable → is a interface if used then we can use for loop