Java Reference
In-Depth Information
void sort( Object [ ] arr, Comparator cmp )
Rearranges the elements in the array to be in sorted order, using the order
specified by the comparator.
In Java 5, these methods have been written as generic methods. The generic
sorting algorithms are required to run in
O
(
N
log
N
)
time.
the
List
interface
6.5
A
list
is a collection of items in which the items have a position. The most obvious
example of a list is an array. In an array, items are placed in position 0, 1, etc.
The
List
interface extends the
Collection
interface and abstracts the
notion of a position. The interface in
java.util
adds numerous methods to
the
Collection
interface. We are content to add the three shown in
Figure 6.16.
A
list
is a collec-
tion of items in
which the items
have a position.
The first two methods are
get
and
set
, which are similar to the methods
that we have already seen in
ArrayList
. The third method returns a more flexi-
ble iterator, the
ListIterator
.
The
List
interface
extends the
Collection
inter-
face and abstracts
the notion of a
position.
1
package weiss.util;
2
3
/**
4
* List interface. Contains much less than java.util
5
*/
6
public interface List<AnyType> extends Collection<AnyType>
7
{
8
AnyType get( int idx );
9
AnyType set( int idx, AnyType newVal );
10
11
/**
12
* Obtains a ListIterator object used to traverse
13
* the collection bidirectionally.
14
* @return an iterator positioned
15
* prior to the requested element.
16
* @param pos the index to start the iterator.
17
* Use size() to do complete reverse traversal.
18
* Use 0 to do complete forward traversal.
19
* @throws IndexOutOfBoundsException if pos is not
20
* between 0 and size(), inclusive.
21
*/
22
ListIterator<AnyType> listIterator( int pos );
23
}
figure 6.16
A sample
List
interface
Search WWH ::
Custom Search