| 31. |
What will be the output of the following Java program?
import java.util.*;
class Collection_Algos
{
public static void main(String args[])
{
LinkedList list = new LinkedList();
list.add(new Integer(2));
list.add(new Integer(8));
list.add(new Integer(5));
list.add(new Integer(1));
Iterator i = list.iterator();
Collections.reverse(list);
Collections.sort(list);
while(i.hasNext())
System.out.print(i.next() + " ");
}
}
|
||||||||
|
Answer:
Option (c) |
| 32. |
What will be the output of the following Java program?
import java.util.*;
class Collection_Algos
{
public static void main(String args[])
{
LinkedList list = new LinkedList();
list.add(new Integer(2));
list.add(new Integer(8));
list.add(new Integer(5));
list.add(new Integer(1));
Iterator i = list.iterator();
Collections.reverse(list);
Collections.shuffle(list);
while(i.hasNext())
System.out.print(i.next() + " ");
}
}
|
||||||||
|
Answer:
Option (d) |
| 33. |
Which of these return type of hasNext() method of an iterator?
|
||||||||
|
Answer:
Option (c) |
| 34. |
Which of these methods is used to obtain an iterator to the start of collection?
|
||||||||
|
Answer:
Option (d) |
| 35. |
Which of these methods can be used to move to next element in a collection?
|
||||||||
|
Answer:
Option (a) |
| 36. |
Which of these iterators can be used only with List?
|
||||||||
|
Answer:
Option (b) |
| 37. |
Which of these is a method of ListIterator used to obtain index of previous element?
|
||||||||
|
Answer:
Option (b) |
| 38. |
Which of these exceptions is thrown by remover() method?
|
||||||||
|
Answer:
Option (d) |
| 39. |
What will be the output of the following Java program?
import java.util.*;
class Collection_iterators
{
public static void main(String args[])
{
ListIterator a = list.listIterator();
if(a.previousIndex()! = -1)
while(a.hasNext())
System.out.print(a.next() + " ");
else
System.out.print("EMPTY");
}
}
|
||||||||
|
Answer:
Option (d) |
| 40. |
What will be the output of the following Java program?
import java.util.*;
class Collection_iterators
{
public static void main(String args[])
{
LinkedList list = new LinkedList();
list.add(new Integer(2));
list.add(new Integer(8));
list.add(new Integer(5));
list.add(new Integer(1));
Iterator i = list.iterator();
Collections.reverse(list);
Collections.sort(list);
while(i.hasNext())
System.out.print(i.next() + " ");
}
}
|
||||||||
|
Answer:
Option (d) |