Question: 3.1 (10 points) Try to understand the following program. import java.utilIterator: import java.util.LinkedList public class IteratorDemo public static void main(String[] args) LinkedList cities-new LinkedList iteratorl

 3.1 (10 points) Try to understand the following program. import java.utilIterator:

3.1 (10 points) Try to understand the following program. import java.utilIterator: import java.util.LinkedList public class IteratorDemo public static void main(String[] args) LinkedList cities-new LinkedList iteratorl = citiesiterator(); iterator String> iterator2 = cities. terator(); Systeout.println("Iteratorl type for the datastructure is: " + iteratorl.toString); Systeout.println("Iterator2 type for the datastructure is: " + iterator2.toString); while (iterator1.hasNext))X String cityl- iteratorl.next); String city2-iterator2.nextO: System.out.println( cityl+", "+city2); 3.1.1 What is the expected output (based on your understanding of the code)? 3.1.2 Run the program in Eclipse, and compare the actual output with your answer in 3.1.1. 3.1.3 What did you learn from this example? You may visit the following link for more insights https://sourcemaking.com/design patterns/iterator/iava/1 3.1.4 Modify the program so that a Hashset is used instead of a Linkedlist. Which line(s) should be modified

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!