Video in progress
Collection and Collections: what is the difference between these two names?
Collection is the common interface for List, Set and Queue. Collections is a utility class full of static helper methods: sort, reverse, unmodifiableList, emptyList and so on.
📖 Answer
The names differ by one letter, but they are completely different things.
java.util.Collection<E> is the root of the hierarchy: add, remove, size, contains, iterator and stream are declared here. List, Set and Queue extend it. Map is not a Collection; it is a separate hierarchy.
java.util.Collections is a class you cannot instantiate. It has only static methods:
List<Integer> nums = new ArrayList<>(List.of(5, 2, 9));
Collections.sort(nums); // [2, 5, 9]
Collections.reverse(nums); // [9, 5, 2]
int max = Collections.max(nums); // 9
List<Integer> ro = Collections.unmodifiableList(nums);
The same pair exists for arrays, Array / Arrays: Arrays.sort, Arrays.asList, Arrays.fill.
Sign up to mark studied questions and save your progress.