The java.util.Collections class contains static utility methods
for manipulating collections.
Assume the following declarations have been made:
List list; int i; Comparator comp; Object key; Object obj; Collection coll;
| Returns | Method | Action |
|---|---|---|
| Rearranging - Sorting, Shuffling, . . . | ||
| sort(list) |
Sorts list. Elements must be Comparable. Stable, O(N log N). |
| sort(list, comp) |
Sorts list using Comparator. |
| shuffle(list) |
Puts the elements of list in random order. |
| reverse(list) |
Reverses the elements of list. |
| Searching | ||
i = | binarySearch(list, key) |
Searches in list for key. Elements must be Comparable.
Returns index of element or negative value if not found.
See Searching. |
i = | binarySearch(list, key, comp) |
Searches in list for key using Comparator comp.
Returns index of element or negative value if not found.
See Searching. |
obj = | max(coll) |
|