NEW
Font size
S
M
L
XL
WorksheetsJava-Collections
Total questions: 40
Worksheet time: 40mins
Name
Class
Date
1.
Which of the following statements about arrays is true?
a)
Arrays can be resized after declaration.
b)
Arrays can hold both homogeneous and heterogeneous data elements.
c)
Arrays can hold only homogeneous data type elements.
d)
Arrays are implemented based on some standard data structure.
2.
Which of the following is a limitation of arrays?
a)
They are growable in nature.
b)
They can hold only objects but not primitives.
c)
They are fixed in size.
d)
They are based on some standard data structure.
3.
What is the main advantage of arrays?
a)
They can hold heterogeneous data elements.
b)
They are implemented based on some data structure.
c)
They can represent a huge number of elements using a single variable.
d)
They have ready-made method support.
4.
Which of the following can hold both primitives and object types?
a)
Arrays
b)
Collections
c)
Both Arrays and Collections
d)
Neither Arrays nor Collections
5.
Which of the following is a characteristic of Collections?
a)
They are fixed in size.
b)
They are implemented based on some standard data structure.
c)
They can hold only homogeneous data type elements.
d)
They are recommended for performance point of view.
6.
If you need to represent a group of objects as a single entity, which concept should you opt for?
a)
Arrays
b)
Collection
c)
Primitives
d)
Data structures
7.
Which programming language uses STL (Standard Template Library) for its collection framework?
a)
Java
b)
Python
c)
C++
d)
C#
8.
Which of the following is NOT one of the nine key interfaces of the collection framework?
a)
List
b)
Array
c)
Queue
d)
Map
9.
What kind of data can collections hold?
a)
Only primitives
b)
Only objects
c)
Both primitives and objects
d)
Neither primitives nor objects
10.
From the performance point of view, which of the following is recommended to use?
a)
Arrays
b)
Collections
c)
Both Arrays and Collections
d)
Neither Arrays nor Collections
11.
What is the main purpose of the Collection interface?
a)
To represent a group of objects as key-value pairs.
b)
To provide several utility methods for Collection objects.
c)
To represent a group of individual objects as a single entity.
d)
To ensure that duplicates are not allowed.
12.
Which interface should you use if you want to allow duplicates and preserve insertion order?
a)
Set
b)
SortedSet
c)
List
d)
NavigableSet
13.
Which statement is true about the Set interface?
a)
It allows duplicates and preserves insertion order.
b)
It doesn't allow duplicates and doesn't preserve insertion order.
c)
It is the child interface of List.
d)
It represents a group of objects as key-value pairs.
14.
What does the NavigableSet interface provide?
a)
Methods to represent objects as key-value pairs.
b)
Methods for navigation purposes.
c)
Methods to ensure insertion order is preserved.
d)
Methods to allow duplicates.
15.
Which statement is true about the Map interface?
a)
It is a child interface of Collection.
b)
It represents a group of objects as a single entity.
c)
It represents a group of objects as key-value pairs.
d)
It only allows unique values.
16.
Which interface would you use to represent a group of unique objects according to some sorting order?
a)
Set
b)
Queue
c)
SortedSet
d)
NavigableSet
17.
What is the difference between Collection and Collections in the Java Collection framework?
a)
Collection is a class and Collections is an interface.
b)
Collection is an interface and Collections is a class.
c)
There is no difference; they are the same.
d)
Both are utility classes in java.util.
18.
Which of the following is NOT a legacy character in the collection framework?
a)
Enumeration(I)
b)
Dictionary(AC)
c)
Vector(C)
d)
List(C)
19.
Which interface is not a direct child of the Collection interface?
a)
List
b)
Set
c)
Queue
d)
Map
20.
If you want to represent a group of objects as key va
a)
Set
b)
List
c)
SortedSet
d)
SortedMap
21.
Which of the following is NOT a method present in the Collection interface?
a)
boolean add(Object o);
b)
boolean isEmpty();
c)
boolean put(Object o);
d)
Object[] toArray();
22.
Which interface should you use if you want to preserve the insertion order and allow duplicates?
a)
Set
b)
Queue
c)
List
d)
Map
23.
Which of the following methods is specific to the List interface?
a)
boolean add(Object o);
b)
boolean contains(Object o);
c)
boolean remove(Object o);
d)
Object get(int index);
24.
What is the underlying data structure of LinkedList?
a)
Resizable array
b)
Double LinkedList
c)
Single LinkedList
d)
HashTable
25.
Which among the following is NOT a method in LinkedList to support stack and queue implementation?
a)
void addFirst(Object o);
b)
Object removeFirst();
c)
boolean remove(Object o);
d)
Object removeLast();
26.
Which of the following is true about Vector?
a)
The underlying data structure is a double LinkedList.
b)
It does not allow null insertion.
c)
Every method in Vector is synchronized.
d)
It does not preserve insertion order.
27.
What is the default initial capacity of a Vector?
a)
5
b)
10
c)
15
d)
20
28.
Which method is used in Vector to get the first element?
a)
Object get(int index);
b)
Object first();
c)
Object elementAt(int index);
d)
Object firstElement();
29.
What will be the capacity of a Vector after adding 11 elements if it was initialized with a default capacity?
a)
10
b)
11
c)
15
d)
20
30.
Which class or interface provides a method to check if a Collection object is empty?
a)
List
b)
Set
c)
Vector
d)
Collection
31.
Which cursor can be used to move in both forward and backward directions?
a)
Enumeration
b)
Iterator
c)
ListIterator
d)
None of the above
32.
Which method is used to determine if there are more elements in an Enumeration?
a)
hasNext()
b)
hasMoreElements()
c)
hasMore()
d)
nextElement()
33.
Which cursor allows replacement of objects while iterating?
a)
Enumeration
b)
Iterator
c)
ListIterator
d)
Both Iterator and ListIterator
34.
Which of the following is NOT a method of the ListIterator interface?
a)
hasPrevious()
b)
previousIndex()
c)
lastElement()
d)
add(Object new)
35.
What is the limitation of the ListIterator?
a)
It can only move in a single direction.
b)
It cannot perform removal operations.
c)
It is applicable only for List objects.
d)
It cannot add new objects.
36.
Which of the following is a legacy cursor?
a)
Enumeration
b)
Iterator
c)
ListIterator
d)
Both Iterator and ListIterator
37.
Using which cursor can we perform both read and remove operations?
a)
Enumeration
b)
Iterator
c)
ListIterator
d)
Both Iterator and ListIterator
38.
The `set(Object new)` method, associated with which cursor, is used for replacement?
a)
Enumeration
b)
Iterator
c)
ListIterator
d)
None of the above
39.
Which cursor is applicable only for legacy classes?
a)
Enumeration
b)
Iterator
c)
ListIterator
d)
None of the above
40.
How can you get a ListIterator object?
a)
Using `elements()` method
b)
Using `iterator()` method
c)
Using `listIterator()` method
d)
Using `next()` method
Reset
