Ask Questions?

View Latest Questions


 
 

Collections Class
Posted on: July 26, 2006 at 12:00 AM
The java.util.Collections class contains static utility methods for manipulating collections.

Java Notes

Collections Class

The java.util.Collections class contains static utility methods for manipulating collections.

Some useful Collections methods

Assume the following declarations have been made:

   List list; int i; Comparator comp; 
   Object key; Object obj; Collection coll;
   
ReturnsMethodAction
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)