Collections Framework In Java - Study Mode

[#171] What will be the output of the following Java program? import java.util.*
class Maps
{
public static void main(String args[])
{
HashMap obj = new HashMap()
obj.put("A", new Integer(1))
obj.put("B", new Integer(2))
obj.put("C", new Integer(3))
System.out.println(obj)
}
}
Correct Answer

(D) {A=1, B=2, C=3}

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

(B) 1 5 8 2

[#173] 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(5))
System.out.println(obj.elementAt(1))
}
}
Correct Answer

(C) 2

[#174] What will be the output of the following Java code? import java.util.*
class stack
{
public static void main(String args[])
{
Stack obj = new Stack()
obj.push(new Integer(3))
obj.push(new Integer(2))
obj.pop()
obj.push(new Integer(5))
System.out.println(obj)
}
}
Correct Answer

(A) [3, 5]

[#175] What is the relation between hashset and hashmap?
Correct Answer

(A) HashSet internally implements HashMap