Collection
A Collection in Java is any group of objects β a list, set, queue or deque. The root interface java.util.Collection defines the common operations: add, remove, contains, size, iterator. Map is related but not a Collection.
The hierarchy
Collection
βββ List β ArrayList, LinkedList, CopyOnWriteArrayList
βββ Set β HashSet, LinkedHashSet, TreeSet, EnumSet
βββ Queue β ArrayDeque, PriorityQueue, LinkedList
βββ Deque β ArrayDeque, LinkedList
Map (not a Collection)
βββ HashMap, LinkedHashMap, TreeMap, ConcurrentHashMap, EnumMap
Example
Collection<String> c = new ArrayList<>();
c.add("Ada");
c.add("Grace");
c.remove("Ada");
System.out.println(c.size()); // 1
System.out.println(c.contains("Grace")); // true
for (String s : c) System.out.println(s);
Collections utility class
The java.util.Collections class (plural!) provides static helpers:
Collections.sort(list);
Collections.reverse(list);
Collections.unmodifiableList(list);
Collections.emptyList();
Collections.singleton(item);
Factory methods (Java 9+)
List<String> list = List.of("a", "b", "c"); // immutable
Set<Integer> set = Set.of(1, 2, 3); // immutable
Map<String, Integer> map = Map.of("a", 1, "b", 2); // immutable