What will the following program print?
import java.util.ArrayList; import java.util.List; import java.util.ListIterator; public class Main { public static void main(String[] args) { List<String> l = new ArrayList<String>(); l.add("A"); l.add("B"); l.add("C"); l.add("D"); l.add("E");//from w w w. j av a 2s .c o m ListIterator<String> i = l.listIterator(); i.next(); i.next(); i.next(); i.next(); i.remove(); i.previous(); i.previous(); i.remove(); System.out.println(l); } }
Select the one correct answer.
(b)
The remove()
method removes the last element returned by either next()
or previous()
method.
The four next()
calls return A, B, C, and D.
D is subsequently removed.
The two previous()
calls return C and B.
B is subsequently removed.