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. |
| sort(list, comp) |
Sorts list. |
| 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.
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) |
Returns maximum valued object in the Collection coll. |
obj = | max(coll, comp) |
Returns maximum valued object in the Collection coll
using Comparator comp. |
obj = | min(coll) |
Returns minimum valued object in the Collection coll. |
obj = | min(coll, comp) |
Returns minimum valued object in the Collection coll
using Comparator comp. |
There are many more methods in Collections, but the above are a good start.