20.7 Collections Methods

Class Collections provides several high-performance algorithms for manipulating collection elements. The algorithms (Fig. 20.5) are implemented as static methods. The methods sort, binarySearch, reverse, shuffle, fill and copy operate on Lists. Methods min, max, addAll, frequency and disjoint operate on Collections.

Fig. 20.5 Collections methods.

Method Description
sort Sorts the elements of a List.
binarySearch Locates an object in a List.
reverse Reverses the elements of a List.
shuffle Randomly orders a List’s elements.
fill Sets every List element to refer to a specified object.
copy Copies references from one List into another.
min Returns the smallest element in a Collection.
max Returns ...

Get Java How to Program (early objects), 9/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.