Java Reference
In-Depth Information
•Method
clear
(p. 694) removes elements from a
List
.
•Method
toArray
(p. 695) returns the contents of a collection as an array.
Section 16.7 Collections Methods
• Algorithms
sort
(p. 697),
binarySearch
,
reverse
(p. 702),
shuffle
(p. 700),
fill
(p. 702),
copy
,
addAll
(p. 693),
frequency
and
disjoint
operate on
List
s. Algorithms
min
and
max
(p. 703) operate on
Collections
.
•Algorithm
addAll
appends all the elements in an array to a collection (p. 706),
frequency
(p. 706) calculates how many elements in the collection are equal to the specified element, and
disjoint
(p. 706) determines whether two collections have elements in common.
• Algorithms
min
and
max
find the smallest and largest items in a collection.
•The
Comparator
interface (p. 697) provides a means of sorting a
Collection
's elements in an or-
der other than their natural order.
•
Collections
method
reverseOrder
(p. 698) returns a
Comparator
object that can be used with
sort
to sort a collection's elements in reverse order.
•Algorithm
shuffle
(p. 700) randomly orders the elements of a
List
.
•Algorithm
binarySearch
(p. 704) locates an
Object
in a sorted
List
.
Section 16.8
Stack
Class of Package
java.util
• Class
Stack
(p. 708) extends
Vector
.
Stack
method
push
(p. 709) adds its argument to the top
of the stack. Method
pop
(p. 710) removes the top element of the stack. Method
peek
returns a
reference to the top element without removing it.
Stack
method
isEmpty
(p. 710) determines
whether the stack is empty.
Section 16.9 Class
PriorityQueue
and Interface
Queue
• Interface
Queue
(p. 710) extends interface
Collection
and provides additional operations for in-
serting, removing and inspecting elements in a queue.
•
PriorityQueue
(p. 710) implements interface
Queue
and orders elements by their natural order-
ing or by a
Comparator
object that's supplied to the constructor.
•
PriorityQueue
method
offer
(p. 710) inserts an element at the appropriate location based on
priority order. Method
poll
(p. 710) removes the highest-priority element of the priority queue.
Method
peek
(
peek
) gets a reference to the highest-priority element of the priority queue. Meth-
od
clear
(p. 710) removes all elements in the priority queue. Method
size
(p. 710) gets the
number of elements in the priority queue.
Section 16.10 Sets
•A
Set
(p. 711) is an unordered
Collection
that contains no duplicate elements.
HashSet
(p. 711)
stores its elements in a hash table.
TreeSet
(p. 711) stores its elements in a tree.
• Interface
SortedSet
(p. 712) extends
Set
and represents a set that maintains its elements in sort-
ed order. Class
TreeSet
implements
SortedSet
.
•
TreeSet
method
headSet
(p. 712) gets a
TreeSet
view containing elements that are less than a
specified element. Method
tailSet
(p. 713) gets a
TreeSet
view containing elements that are
greater than or equal to a specified element. Any changes made to these views are made to the
original
TreeSet
.
Section 16.11 Maps
•
Map
s (p. 714) store key-value pairs and cannot contain duplicate keys.
HashMap
s (p. 714) and
Hashtable
s (p. 714) store elements in a hash table, and
TreeMap
s (p. 714) store elements in a tree.