What is the difference between the Arrays and Collections utility classes?
Quick Answer
Arrays (java.util.Arrays) provides static helper methods for working with plain arrays: sort(), binarySearch(), fill(), equals(), asList(), and copyOf(). Collections (java.util.Collections) provides equivalent static helpers for Collection/List/Set/Map objects: sort(), binarySearch(), unmodifiableX(), synchronizedX(), max()/min(), and shuffle(). They mirror each other conceptually but operate on different data structures and aren't interchangeable.
Detailed Answer
Both are static-method-only utility classes in java.util, mirroring similar operations for two different data structures:
Arrays: operates on plain Java arrays (int[],String[], etc.) —Arrays.sort(arr),Arrays.binarySearch(arr, key),Arrays.fill(arr, val),Arrays.equals(a, b)(element-wise, unlike==),Arrays.copyOf(arr, newLength), andArrays.asList(arr)(returns a fixed-sizeListview backed by the array — its size can't change, though existing elements can be set).Collections: operates onCollection/List/Set/Mapobjects —Collections.sort(list),Collections.binarySearch(list, key),Collections.max(coll)/min(coll),Collections.shuffle(list),Collections.unmodifiableList(list),Collections.synchronizedList(list), and factory helpers likeCollections.emptyList()/singletonList(x).
int[] nums = {3, 1, 2};
Arrays.sort(nums); // arrays
List<Integer> list = new ArrayList<>(List.of(3, 1, 2));
Collections.sort(list); // collections
A common gotcha: Arrays.asList(arr) returns a fixed-size list backed directly by the array — calling .add()/.remove() on it throws UnsupportedOperationException, and mutating an element through the list writes back into the original array. To get a fully independent, resizable list, wrap it: new ArrayList<>(Arrays.asList(arr)).