Collections Framework In Java - Study Mode

[#126] What will be the output of the following Java program? import java.util.*

class Bitset
{
public static void main(String args[])
{
BitSet obj = new BitSet(5)

for (int i = 0

i < 5

++i)
obj.set(i)

obj.clear(2)

System.out.print(obj)

}
}
Correct Answer

(A) {0, 1, 3, 4}

[#127] 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()

while(i.hasNext())
System.out.print(i.next() + " ")

}
}
Correct Answer

(A) 2 8 5 1

[#128] 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() + " ")

}
}
Correct Answer

(C) 1 2 5 8

[#129] What will be the output of the following Java program? import java.util.*

class Output
{
public static void main(String args[])
{
HashSet obj = new HashSet()

obj.add("A")

obj.add("B")

obj.add("C")

System.out.println(obj + " " + obj.size())

}
}
Correct Answer

(B) [A, B, C] 3

[#130] What will be the output of the following Java code? import java.lang.reflect.*

class Additional_packages
{
public static void main(String args[])
{
try
{
Class c = Class.forName("java.awt.Dimension")

Constructor constructors[] = c.getConstructors()

for (int i = 0

i < constructors.length

i++)
System.out.println(constructors[i])

}
catch (Exception e)
{
System.out.print("Exception")

}
}
}
Correct Answer

(A) Program prints all the constructors of 'java.awt.Dimension' package