Collections Framework In Java - Study Mode

[#166] 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() + " ")
}
}
Correct Answer

(D) Any random order

[#167] What will be the output of the following Java code? import java.util.*
class vector
{
public static void main(String args[])
{
Vector obj = new Vector(4,2)
obj.addElement(new Integer(3))
obj.addElement(new Integer(2))
obj.addElement(new Integer(6))
obj.insertElementAt(new Integer(8), 2)
System.out.println(obj)
}
}
Correct Answer

(D) [3, 2, 8, 6]

[#168] What will be the output of the following Java code? import java.util.*
class properties
{
public static void main(String args[])
{
Properties obj = new Properties()
obj.put("AB", new Integer(3))
obj.put("BC", new Integer(2))
obj.put("CD", new Integer(8))
System.out.print(obj.keySet())
}
}
Correct Answer

(B) [AB, BC, CD]

[#169] What will be the output of the following Java program? import java.util.*
class Array
{
public static void main(String args[])
{
int array[] = new int [5]
for (int i = 5
i > 0
i--)
array[5 - i] = i
Arrays.sort(array)
for (int i = 0
i < 5
++i)
System.out.print(array[i])
}
}
Correct Answer

(A) 12345

[#170] What will be the output of the following Java program? import java.util.*
class Arraylist
{
public static void main(String args[])
{
ArrayList obj1 = new ArrayList()
ArrayList obj2 = new ArrayList()
obj1.add("A")
obj1.add("B")
obj2.add("A")
obj2.add(1, "B")
System.out.println(obj1.equals(obj2))
}
}
Correct Answer

(C) true