In Java, which method is used to add an element to a collection in the Java Collections Framework?
A. `insert()`
B. `put()`
C. `add()`
D. `append()`
Select an option to see the answer and solution.
What is the purpose of the `toArray()` method in the Java Collections Framework?
A. It sorts the collection
B. It converts a collection to an array
C. It reverses the collection
D. None of These
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?
A. `Set`
B. `ArrayList`
C. `Collections`
D. `List`
Select an option to see the answer and solution.
What is the purpose of the `Iterator` interface in the Java Collections Framework?
A. It defines a comparison function for ordering elements
B. It represents a synchronized collection
C. It provides methods for hashing elements
D. It provides a way to iterate over a collection's elements
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?
A. `clear()`
B. `removeAll()`
C. `erase()`
D. `purge()`
Select an option to see the answer and solution.
What is the purpose of the `Map.Entry` interface in the Java Collections Framework?
A. It provides methods for hashing elements
B. It represents a synchronized collection
C. It defines a comparison function for ordering elements
D. It represents a key-value pair in a map
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?
A. `synchronize()`
B. `synchronizedList()`
C. `Collections.synchronizedCollection()`
D. `makeSynchronized()`
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?
A. A `LinkedHashSet` allows duplicate elements, while a `HashSet` does not
B. A `LinkedHashSet` maintains the insertion order of elements, while a `HashSet` does not
C. A `HashSet` allows duplicate elements, while a `LinkedHashSet` does not
D. None of These
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?
A. `makeSynchronizedMap()`
B. `synchronized()`
C. `Collections.synchronizedMap()`
D. `synchronizeMap()`
Select an option to see the answer and solution.
What is the purpose of the `Collections.reverse()` method in the Java Collections Framework?
A. It removes all elements from a list
B. It sorts a list in ascending order
C. It adds elements to a list
D. It reverses the order of elements in a list
Select an option to see the answer and solution.
Which of these method can be used to increase the capacity of ArrayList object manually?
A. Capacity()
B. increaseCapacity()
C. increasecapacity()
D. ensureCapacity()
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);
}
}A. [A, B, C]
B. [D, B, C]
C. [A, B, C, D]
D. [D, A, B, C]
Select an option to see the answer and solution.
What is Collection in Java?
A. A group of objects
B. A group of classes
C. A group of interfaces
D. None of the mentioned
Select an option to see the answer and solution.
Which of these methods can convert an object into a List?
A. SetList()
B. ConvertList()
C. singletonList()
D. CopyList()
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?
A. Reference equality
B. Name equality
C. Hashcode equality
D. Length equality
Select an option to see the answer and solution.
Which of these is static variable defined in Collections?
A. EMPTY_SET
B. EMPTY_LIST
C. EMPTY_MAP
D. All of the mentioned
Select an option to see the answer and solution.
Which of these methods is used to add elements in vector at specific location?
A. add()
B. set()
C. AddElement()
D. addElement()
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() + " ");
}
}A. 2 8 5 1
B. 1 5 8 2
C. 1 2 5 8
D. 2 1 8 5
Select an option to see the answer and solution.
What is the difference between Queue and Stack?
A. Stack is LIFO; Queue is FIFO
B. Queue is LIFO; Stack is FIFO
C. Stack and Queue is FIFO
D. Stack and Queue is LIFO
Select an option to see the answer and solution.