Collections Framework In Java - Study Mode

[#146] 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.capacity())
}
}
Correct Answer

(C) 4

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

(B) 1 5 8 2

[#148] 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.ensureCapacity(3)
System.out.println(obj.size())
}
}
Correct Answer

(A) 1

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

(D) EMPTY

[#150] What will be the output of the following Java program? import java.lang.reflect.*
class Additional_packages
{
public static void main(String args[])
{
try
{
Class c = Class.forName("java.awt.Dimension")
Method methods[] = c.getMethods()
for (int i = 0
i < methods.length
i++)
System.out.println(methods[i])
}
catch (Exception e)
{
System.out.print("Exception")
}
}
}
Correct Answer

(B) Program prints all the methods of 'java.awt.Dimension' package