Java Reference
In-Depth Information
FIGURE 12-3
A list of numbers that identify runners in the order in which
they finished a race
16
4
33
27
The Java program in Listing 12-2 shows how we can perform this task by using the ADT list. It
assumes that the class AList implements the Java interface ListInterface that you saw in the pre-
vious section. Since ListInterface assumes that the items in the list are objects, we will treat each
runner's identifying number as a string.
LISTING 12-2
A client of a class that implements ListInterface
public class ListClient
{
public static void main(String[] args)
{
testList();
} // end main
public static void testList()
{
ListInterface<String> runnerList = new AList<String>();
// runnerList has only methods in ListInterface
runnerList.add("16"); // winner
runnerList.add(" 4"); // second place
runnerList.add("33"); // third place
runnerList.add("27"); // fourth place
displayList(runnerList);
} // end testList
public static void displayList(ListInterface<String> list)
{
Search WWH ::




Custom Search