img
Method
Description
Sor ts the elements of list as determined by comp.
static <T>
void sor t(List<T> list,
Comparator<? super T> comp)
Sor ts the elements of list as determined by their
static <T extends Comparable<? super T>>
void sor t(List<T> list)
natural ordering.
static void swap(List<?> list,
Exchanges the elements in list at the indices
int idx1, int idx2)
specified by idx1 and idx2.
Returns a thread-safe collection backed by c.
static <T> Collection<T>
synchronizedCollection(Collection<T> c)
static <T> List<T> synchronizedList(List<T> list)
Returns a thread-safe list backed by list.
Returns a thread-safe map backed by m.
static <K, V> Map<K, V>
synchronizedMap(Map<K, V> m)
static <T> Set<T> synchronizedSet(Set<T> s)
Returns a thread-safe set backed by s.
Returns a thread-safe sor ted map backed by sm.
static <K, V> Sor tedMap<K, V>
synchronizedSor tedMap(Sor tedMap<K, V> sm)
Returns a thread-safe set backed by ss.
static <T> Sor tedSet<T>
synchronizedSor tedSet(Sor tedSet<T> ss)
Returns an unmodifiable collection backed by c.
static <T> Collection<T>
unmodifiableCollection(
Collection<? extends T> c)
Returns an unmodifiable list backed by list.
static <T> List<T>
unmodifiableList(List<? extends T> list)
Returns an unmodifiable map backed by m.
static <K, V> Map<K, V>
unmodifiableMap(Map<? extends K,
? extends V> m)
Returns an unmodifiable set backed by s.
static <T> Set<T>
unmodifiableSet(Set<? extends T> s)
static <K, V> Sor tedMap<K, V>
Returns an unmodifiable sor ted map backed
by sm.
unmodifiableSor tedMap(Sor tedMap<K,
? extends V> sm)
Returns an unmodifiable sor ted set backed by ss.
static <T> Sor tedSet<T>
unmodifiableSor tedSet(Sor tedSet<T> ss)
TABLE 17-14
The Algorithms Defined by Collections (continued)
Several of the methods can throw a ClassCastException, which occurs when an attempt
is made to compare incompatible types, or an UnsupportedOperationException, which occurs
when an attempt is made to modify an unmodifiable collection. Other exceptions are
possible, depending on the method.
One thing to pay special attention to is the set of checked methods, such as
checkedCollection( ), which returns what the API documentation refers to as a "dynamically
typesafe view" of a collection. This view is a reference to the collection that monitors insertions
into the collection for type compatibility at run time. An attempt to insert an incompatible
element will cause a ClassCastException. Using such a view is especially helpful during
debugging because it ensures that the collection always contains valid elements. Related
methods include checkedSet( ), checkedList( ), checkedMap( ), and so on. They obtain a
type-safe view for the indicated collection.
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home