Collections.min() and Collections.max() scan a list and return the smallest or largest element:
ArrayList<Integer> nums = new ArrayList<>();
nums.add(30);
nums.add(10);
nums.add(20);
int smallest = Collections.min(nums); // 10
int largest = Collections.max(nums); // 30
Both methods iterate through the entire list once, so they run in time and space. They work on any list whose elements implement Comparable, which includes Integer, Double, String, and Character.
If the list is empty, both methods throw a NoSuchElementException. Always check .isEmpty() or .size() before calling them on a list that might have no elements.