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

2/9

Page

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

In Java, which method is used to add an element to a collection in the Java Collections Framework?

Select an option to see the answer and solution.

What is the purpose of the `toArray()` method in the Java Collections Framework?

Select an option to see the answer and solution.

In the Java Collections Framework, which class provides methods to manipulate the size of a list and its elements?

Select an option to see the answer and solution.

What is the purpose of the `Iterator` interface in the Java Collections Framework?

Select an option to see the answer and solution.

Which method is used to remove all elements from a collection in the Java Collections Framework?

Select an option to see the answer and solution.

What is the purpose of the `Map.Entry` interface in the Java Collections Framework?

Select an option to see the answer and solution.

In the Java Collections Framework, which method is used to obtain a synchronized (thread-safe) version of a collection?

Select an option to see the answer and solution.

What is the primary difference between a `HashSet` and a `LinkedHashSet` in the Java Collections Framework?

Select an option to see the answer and solution.

In Java, which method is used to obtain a synchronized (thread-safe) map from an existing map in the Java Collections Framework?

Select an option to see the answer and solution.

What is the purpose of the `Collections.reverse()` method in the Java Collections Framework?

Select an option to see the answer and solution.

Which of these method can be used to increase the capacity of ArrayList object manually?

Select an option to see the answer and solution.

What will be the output of the following Java code snippet?
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.addFirst("D");
        System.out.println(obj);
    }
}

Select an option to see the answer and solution.

What is Collection in Java?

Select an option to see the answer and solution.

Which of these methods can convert an object into a List?

Select an option to see the answer and solution.

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.get("B"));
    }
}

Select an option to see the answer and solution.

What is the premise of equality for IdentityHashMap?

Select an option to see the answer and solution.

Which of these is static variable defined in Collections?

Select an option to see the answer and solution.

Which of these methods is used to add elements in vector at specific location?

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

Select an option to see the answer and solution.

What is the difference between Queue and Stack?

Select an option to see the answer and solution.