publictreeSet(SortedSet<E> set)
Creates a new treeSet whose initial contents will be the same as those in
set and that is sorted in the same way as set.
21.6. List
The List
ordereach element exists in a particular position in the collection, indexed from 0 to list.size()-1. Or,
in other words, a List defines a sequence of elements. This requires a refinement of the contracts of several
methods inherited from Collection: when you add an element, it is placed at the end of the list; When
you remove the nth element from the list, the element that was after it is shifted over, becoming the new nth
element; and the toArray methods fill in the array in the list's order.
List also adds several methods that make sense in an ordered collection:
public Eget(int index)
Returns the indexth entry in the list.
public Eset(int index, E elem)
Sets the indexth entry in the list to elem, replacing the previous element and
returning it. (Optional)
public voidadd(int index, E elem)
Adds the entry elem to the list at the indexth position, shifting every
element farther in the list down one position. (Optional)
public Eremove(int index)
Removes and returns the indexth entry in the list, shifting every element
farther in the list up one position. (Optional)
public intindexOf(Object elem)
Returns the index of the first object in the list that is equal to elem, or that
is null if elem is null. Returns 1 if no match is found.
public intlastIndexOf(Object elem)
Returns the index of the last object in the list that is equal to elem, or that
is null if elem is null. Returns 1 if no match is found.
public List<E>subList(int min, int max)
Returns a List that is a view on this list over the range, starting with min
up to, but not including, max. For example, subList(1,5) would return a
list containing elements number 1, 2, 3, and 4 from this list. The returned list
is backed by this list, so changes made to the returned list are reflected in this
list. Changes made directly to the backing list are not guaranteed to be visible