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.length() + " " + obj.size());
}
}A. 4 64
B. 5 64
C. 5 128
D. 4 128
Select an option to see the answer and solution.
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]);;
}
}A. 12345
B. 54321
C. 1234
D. 5432
Select an option to see the answer and solution.
Which of these methods can be used to move to next element in a collection?
A. next()
B. move()
C. shuffle()
D. hasNext()
Select an option to see the answer and solution.
Which of this method is used to change an element in a LinkedList Object?
A. change()
B. set()
C. redo()
D. add()
Select an option to see the answer and solution.
What will be the output of the following Java program?
import java.util.*;
class Linkedlist
{
public static void main(String args[])
{
LinkedList obj = new LinkedList();
obj.add("A");
obj.add("B");
obj.add("C");
obj.removeFirst();
System.out.println(obj);
}
}A. [A, B]
B. [B, C]
C. [A, B, C, D]
D. [A, B, C]
Select an option to see the answer and solution.
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));
obj.removeAll(obj);
System.out.println(obj.isEmpty());
}
}Select an option to see the answer and solution.
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));
obj.remove(new String("A"));
System.out.print(obj);
}
}A. {C=8, B=2}
B. [C=8, B=2]
C. {A=3, C=8, B=2}
D. [A=3, C=8, B=2]
Select an option to see the answer and solution.
Which of these classes implements Set interface?
A. ArrayList
B. HashSet
C. LinkedList
D. DynamicList
Select an option to see the answer and solution.
Which of this interface is not a part of Java's collection framework?
A. List
B. Set
C. SortedMap
D. SortedList
Select an option to see the answer and solution.
Which of this method is used to make all elements of an equal to specified value?
A. add()
B. fill()
C. all()
D. set()
Select an option to see the answer and solution.
Which of these interface declares core method that all collections will have?
A. set
B. EventListner
C. Comparator
D. Collection
Select an option to see the answer and solution.
What is the difference between TreeSet and SortedSet?
A. TreeSet is more efficient than SortedSet
B. SortedSet is more efficient than TreeSet
C. TreeSet is an interface; SortedSet is a concrete class
D. SortedSet is an interface; TreeSet is a concrete class
Select an option to see the answer and solution.
Map implements collection interface?
Select an option to see the answer and solution.
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");
Field fields[] = c.getFields();
for (int i = 0; i < fields.length; i++)
System.out.println(fields[i]);
}
catch (Exception e)
{
System.out.print("Exception");
}
}
}A. Program prints all the constructors of 'java.awt.Dimension' package
B. Program prints all the methods of 'java.awt.Dimension' package
C. Program prints all the data members of 'java.awt.Dimension' package
D. program prints all the methods and data member of 'java.awt.Dimension' package
Select an option to see the answer and solution.
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() + " ");
}
}A. 2 8 5 1
B. 1 5 8 2
C. 1 2 5 8
D. Any random order
Select an option to see the answer and solution.
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);
}
}A. [3, 2, 6]
B. [3, 2, 8]
C. [3, 2, 6, 8]
D. [3, 2, 8, 6]
Select an option to see the answer and solution.
Which of these methods sets every element of a List to a specified object?
A. set()
B. fill()
C. Complete()
D. add()
Select an option to see the answer and solution.
Which of these methods can be used to delete the last element in a LinkedList object?
A. remove()
B. delete()
C. removeLast()
D. deleteLast()
Select an option to see the answer and solution.
Which of these method is used to add an element to the start of a LinkedList object?
A. add()
B. first()
C. AddFirst()
D. addFirst()
Select an option to see the answer and solution.
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());
}
}A. {AB, BC, CD}
B. [AB, BC, CD]
C. [3, 2, 8]
D. {3, 2, 8}
Select an option to see the answer and solution.