Vidyalelo
Java Programming · all questions

Java Collections Framework
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

179

Questions

7/9

Page

Pick an option on a question to see the right answer and solution.

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);
        System.out.print(obj.get(3));
    }
}

Select an option to see the answer and solution.

Which of these are legacy classes?

Select an option to see the answer and solution.

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);
    }
}

Select an option to see the answer and solution.

Which of these class can generate an array which can increase and decrease in size automatically?

Select an option to see the answer and solution.

What are the initial capacity and load factor of HashSet?

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();
  while(i.hasNext())
      System.out.print(i.next() + " ");
    }
}

Select an option to see the answer and solution.

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() + " ");
    }
}

Select an option to see the answer and solution.

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());
    }
}

Select an option to see the answer and solution.

Do we have get(Object o) method in HashSet.

Select an option to see the answer and solution.

Which of these standard collection classes implements a linked list data structure?

Select an option to see the answer and solution.

Which of these methods deletes all the elements from invoking collection?

Select an option to see the answer and solution.

What does Collections.emptySet() return?

Select an option to see the answer and solution.

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);
    }
}

Select an option to see the answer and solution.

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);
   }
}

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));
        System.out.println(obj.capacity());
    }
}

Select an option to see the answer and solution.

Which of these object stores association between keys and values?

Select an option to see the answer and solution.

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() + " ");
    }
}

Select an option to see the answer and solution.

Which of these methods can be used to search an element in a list?

Select an option to see the answer and solution.

How can we remove an object from ArrayList?

Select an option to see the answer and solution.

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());
    }
}

Select an option to see the answer and solution.