lab 14 3 7 1

background image

1 - 1

Fundamentals of Java Programming Lab 14.3.7.1

Copyright

 2003, Cisco Systems, Inc.

Lab 14.3.7.1

ListIterators


Estimated Time:
20 minutes

Learning Objectives:

• In this lab activity, the student will use ListIterators to scan through a Collection.

Description/Scenario:

• A collection can be scanned using an iterator. Two iterator interfaces are available in

the collection framework. They are the Iterator and its subclass the ListIterator. Use
the ListIterator with list objects. Iterators provide methods for scanning through any
collection. In a set, the order is non-deterministic. This means it is not determined by
the sequence in which it was added, or by some special key value. When using an
iterator to move over a set, the iteration moves forward (but not backwards) through
the list elements.

• Iterator objects provide for scanning through the list and for adding and removing

elements from the collection.

• A list object also supports a ListIterator, which allows the list to be scanned

backwards.

• Use ListIterators to traverse through a Collection of Point objects created in the

previous lab14.3.5.


File Management:

Open BlueJ. Click on Project from the BlueJ main menu and select New. In the New
Project window and in the Look in: list box select c:\. Now, double click the javacourse
folder listed in the text window and a different New Project window opens with javacourse
in the Look in: list box. Now, double click the chap14 folder listed in the text window and a
different New Project window opens with chap14 in the Look in: list box. Type lab14.3.7.1
in the File name text box and click on Create to create a lab14.3.7.1 subfolder in the
chap14 folder. Import the Line class from lab14.3.5.


Tasks:

Step 1 Use of ListIterator

a. Import the class Line from previous lab. Add another method called

listIterator(), which returns a ListIterator object that can be used to iterate

through the collection of Point objects. A collection can be scanned using an iterator.
There are two iterator interfaces available in the collection framework. The iterator
and its subclass the ListIterator.

b. Use the ListIterator with list objects. When using an iterator to move over a set, the

iteration moves forward through the list elements. The ListIterator provides additional
methods for scanning forward and backwards through the collection.

Step 2 Testing the program

a. Add statements to the main method to test the listIterator() method and the

ListIterator object it returns.



Document Outline


Wyszukiwarka

Podobne podstrony:
elektro lab 14
lab 14 4 1 1
lab 14 4 3
Lab 14 - rozszerzalność, Skały14, Nr
Lab 14 - rozszerzalność, Skały141, Nr
lab 14
lab 14, MIBM WIP PW, fizyka 2, sprawka fiza 2, fizyka, fizyka
lab 14 4 1 2
PW LAB 14
IE RS lab 14 diagram
IE RS lab 14 solutions
lab 14 3 5
lab 14 1 8
lab 14 3 7 2
Lab 14 - rozszerzalność, wsp.ciep.roz.14
lab t 14, t14 tabela pomiarowa, Przepływ współprądowy
Lab 14 id 257442 Nieznany
elektro lab 14

więcej podobnych podstron