Collections Framework In Java - Study Mode

[#141] What will be the output of the following Java code? import java.util.*
class hashtable
{
public static void main(String args[])
{
Hashtable obj = new Hashtable()
obj.put("A", new Integer(3))
obj.put("B", new Integer(2))
obj.put("C", new Integer(8))
System.out.print(obj.contains(new Integer(5)))
}
}
Correct Answer

(D) false

[#142] 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.shuffle(list)
i.next()
i.remove()
while(i.hasNext())
System.out.print(i.next() + " ")
}
}
Correct Answer

(B) 2 1 8

[#143] What will be the output of the following Java program? import java.util.*
class Output
{
public static void main(String args[])
{
ArrayList obj = new ArrayList()
obj.add("A")
obj.add(0, "B")
System.out.println(obj.size())
}
}
Correct Answer

(C) 2

[#144] What will be the output of the following Java code? 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}

[#145] What will be the output of the following Java code snippet? public class Demo
{
public static void main(String[] args)
{
Map sampleMap = new TreeMap ()
sampleMap.put(1, null)
sampleMap.put(5, null)
sampleMap.put(3, null)
sampleMap.put(2, null)
sampleMap.put(4, null)
System.out.println(sampleMap)
}
}
Correct Answer

(A) {1=null, 2=null, 3=null, 4=null, 5=null}