19.6. Collections Algorithms

The collections framework provides several high-performance algorithms for manipulating collection elements. These algorithms are implemented as static methods of class Collections (Fig. 19.7). Algorithms sort, binarySearch, reverse, shuffle, fill and copy operate on Lists. Algorithms min, max, addAll, frequency and disjoint operate on Collections.

Figure 19.7. Collections algorithms.
AlgorithmDescription
sortSorts the elements of a List.
binarySearchLocates an object in a List.
reverseReverses the elements of a List.
shuffleRandomly orders a List’s elements.
fillSets every List element to refer to a specified object.
copyCopies references from one List into another.
minReturns the smallest element in a Collection.
maxReturns ...

Get Java™ How to Program, Seventh Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.