Consider the following Java Code:
What is the output when this code is executed?
import java.util.LinkedList;
import java.util.ListIterator;
class Main {
public static void main(String[] args) {
LinkedList myLList = new LinkedList();myLList.addFirst("Ali");myLList.addFirst("Omar");myLList.addLast("Sara");ListIterator myiterator = myLList.listIterator();myiterator.next();myiterator.next();myiterator.add("Reem");myiterator.previous();myiterator.add("Ahmad");myiterator.add("Khaled");myiterator.previous();myiterator.remove();System.out.println(myLList);myiterator.next();myiterator.next(); System.out.println("MyList Backward iteration :"); while(myiterator.hasPrevious()) System.out.println(myiterator.previous()); System.out.println("---------------------"); }}
myLList.addFirst("Ali");
myLList.addFirst("Omar");
myLList.addLast("Sara");
ListIterator myiterator = myLList.listIterator();myiterator.next();myiterator.next();myiterator.add("Reem");myiterator.previous();myiterator.add("Ahmad");myiterator.add("Khaled");myiterator.previous();myiterator.remove();System.out.println(myLList);myiterator.next();myiterator.next(); System.out.println("MyList Backward iteration :"); while(myiterator.hasPrevious()) System.out.println(myiterator.previous()); System.out.println("---------------------"); }}
myiterator.next();
myiterator.add("Reem");
myiterator.previous();
myiterator.add("Ahmad");
myiterator.add("Khaled");
myiterator.remove();
System.out.println(myLList);
System.out.println("MyList Backward iteration :");
while(myiterator.hasPrevious())
System.out.println(myiterator.previous());
System.out.println("---------------------");
}
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here