Question: For this question, we use the list iterator of Java. This iterator has a method add. Hence, the iterator can add elements to a list.

For this question, we use the list iterator of Java. This iterator has a method add. Hence, the iterator can add elements to a list.

http://download.oracle.com/javase/8/docs/api/java/util/ListIterator.htm

import java.util.ListIterator; import java.util.LinkedList; public class Test { public static void main( String[] args ) { LinkedList a, b; a = new LinkedList(); b = new LinkedList(); a.add("alpha"); a.add("bravo"); a.add("tango"); a.add("charlie"); ListIterator i, j; i = a.listIterator(); j = b.listIterator(); while (i.hasNext()) { j.add(i.next()); } System.out.println(a); System.out.println(b); } }

What is the result of the execution of the above Java program?

1.charlie, tango, bravo, alpha charlie, tango, bravo, alpha

2.alpha, bravo, tango, charlie alpha, bravo, tango, charlie

3.charlie, tango, bravo, alpha alpha, bravo, tango, charlie

4.alpha, bravo, tango, charlie charlie, tango, bravo, alpha

5.Runs into an infinite loop

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!