Java Reference
In-Depth Information
4.
To allow duplicate elements to be stored in a collection, you need to use a list. A list
not only can store duplicate elements but also allows the user to specify where they are
stored. The user can access elements by an index.
5.
Two types of lists are supported: ArrayList and LinkedList . ArrayList is a
resizable-array implementation of the List interface. All the methods in ArrayList
are defined in List . LinkedList is a linked-list implementation of the List interface.
In addition to implementing the List interface, this class provides the methods for
retrieving, inserting, and removing elements from both ends of the list.
6. Comparator can be used to compare the objects of a class that doesn't implement
Comparable .
7.
The Vector class extends the AbstractList class. Starting with Java 2, Vector has
been the same as ArrayList , except that the methods for accessing and modifying
the vector are synchronized. The Stack class extends the Vector class and provides
several methods for manipulating the stack.
8.
The Queue interface represents a queue. The PriorityQueue class implements Queue
for a priority queue .
Q UIZ
Answer the quiz for this chapter online at www.cs.armstrong.edu/liang/intro10e/quiz.html .
P ROGRAMMING E XERCISES
Sections 20.2-20.7
*20.1
( Display words in ascending alphabetical order ) Write a program that reads
words from a text file and displays all the words (duplicates allowed) in ascend-
ing alphabetical order. The words must start with a letter. The text file is passed
as a command-line argument.
*20.2
( Store numbers in a linked list ) Write a program that lets the user enter num-
bers from a graphical user interface and displays them in a text area, as shown in
FigureĀ 20.17a. Use a linked list to store the numbers. Do not store duplicate num-
bers. Add the buttons Sort , Shuffle , and Reverse to sort, shuffle, and reverse the list.
(a)
(b)
F IGURE 20.17
(a) The numbers are stored in a list and displayed in the text area. (b) The colliding balls are combined.
 
 
Search WWH ::




Custom Search