Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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: 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started