wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Collections Trivia

Total questions: 45

Worksheet time: 45mins

Name
Class
Date
1.

We have a list with 3 elements, i.e. [5,3,1], and the following code is executed.


nums.add(6);

nums.add(0,4);

numbs.remove(1);


What will be the resulting list?

a)

[4,3,6]

b)

[4,5,3,6]

c)

[5,3,1,6]

d)

[4,3,1,6]

2.

a)
b)
c)
d)
3.

a)
b)
c)
d)
4.

a)
b)
c)
d)
5.

a)
b)
c)
d)
6.

a)
b)
7.

a)
b)
8.

a)
b)
9.

a)
b)
c)
10.

a)
b)
c)
11.

a)
b)
c)
d)
12.

a)
b)
c)
13.

a)
b)
14.

a)
b)
c)
d)
15.

a)
b)
c)
d)
16.

a)
b)
c)
d)
17.

a)
b)

-2

c)
d)
18.

a)
b)
c)
d)
19.

a)
b)
c)
d)
20.

a)
b)
21.

The Linked List class implements what interfaces?


Select Multiple

a)

List

b)

Deque

c)

Set

d)

Queue

22.

What are some features of a Linked List?

a)

The elements are inserted in the order of insertion.

b)

It supports duplicate elements.

c)

We can add any number of null elements.

d)

Duplicates are not allowed.

23.

Which interfaces is not apart of the Collection framework?

a)

List

b)

Set

c)

Map

d)

Queue

24.

Which is true about Collection and Collections?


Select Multiple of True

a)

A Collection is an interface, whereas Collections is a class.

b)

Collections is an interface, whereas a Collection is a class.

c)

Collections provides utility methods that can be used to search, sort, and synchronize collection elements.

25.

Which of these does not apply to a TreeSet?

a)

TreeSet does not allow duplicate elements.

b)

TreeSet class doesn’t allow null elements.

c)

The elements are stored in ascending order in a TreeSet.

d)

All are true.

26.

Which is true about TreeMap?

a)

The entries in TreeMap are sorted in the natural ordering of its keys.

b)

It does not allow null keys, however there can be null values.

c)

The TreeMap is not thread-safe, although it can be made thread-safe using the synchronizedMap() method of the Collections class.

d)

All of the above.

27.

Which of the following is a correct difference between ArrayList and LinkedList?

a)

ArrayList uses a doubly linked list whereas the LinkedList uses dynamic array.

b)

ArrayList uses a dynamic array whereas the LinkedList uses doubly linked list.

c)

ArrayList uses a single linked list whereas the LinkedList uses dynamic array.

d)

None

28.

What do you understand of hash-collision in a Hashtable?

a)

If two same keys have the different hash value then it leads to hash-collision.

b)

If two same keys have the same hash value then it leads to hash-collision.

c)

If two different keys have the same hash value then it leads to hash-collision.

d)

None

29.

Which of the following is not true for a fail-fast iterator?

a)

Fail fast immediately reports any failure and fail fast system fails whenever a problem occurs.

b)

Fail fast iterator throws concurrent modification exception while iterating through the collection of objects.

c)

Fail fast system reports the failure right away but the system recovers after the failure.

d)

None

30.

When would you choose to use LinkedList over ArrayList in an application?

a)

LinkedList is preferred when application requires to perform merging or sorting operations.

b)

LinkedList is preferred when applications needs to support insertions or deletions of elements.

c)

LinkedList is preferred when application requires to perform frequent get or search operations.

d)

None

31.

When would you choose to use ArrayList over LinkedList in an application?

a)

ArrayList is preferred when there is more demand for get via index operations.

b)

ArrayList is preferred when there are frequent insertions or deletions required in the application.

c)

ArrayList is preferred when there is growing need of merging or sorting operations.

d)

None

32.

What is the correct difference between HashSet and HashMap?

a)

long

b)

HashSet can contain duplicate elements whereas HashMap contains only unique elements.

c)

HashSet maintains no order whereas HashMap maintains ascending order.

d)

HashSet contains only values whereas HashMap contains the key and value pair.

33.

Which of the following is a correct difference between HashSet and TreeSet?

a)

HashSet maintains no order while TreeSet maintains ascending order.

b)

HashSet can contain duplicate elements whereas TreeSet contains only unique elements.

c)

TreeSet maintains no order while HashSet maintains ascending order.

d)

None

34.

Which of the following is a valid difference between Set and Map?

a)

Set can contain duplicate elements whereas Map contains only unique elements.

b)

Set doesn't maintain any order whereas Map maintains ascending order.

c)

Set contains only values whereas Map contains key and values both.

d)

None

35.

Which of the following is a correct difference between HashMap and Hashtable?

a)

HashMap can contain duplicate elements whereas the Hashtable contains only unique elements.

b)

HashMap is not synchronized while the Hashtable is synchronized.

c)

HashMap contains only values whereas Hashtable contains key and values both.

d)

None

36.

What is the design pattern followed by Iterator?

a)

Factory design pattern

b)

Iterator design pattern

c)

Observer design pattern

d)

None

37.

Which of the following class doesn’t implement the Set interface?

a)

HashSet

b)

LinkedHashSet

c)

TreeSet

d)

None of the above

38.

Which of the following is a correct difference between HashMap and ConcurrentHashMap?

a)

HashMap maintains the inserted elements in random order while ConcurrentHashMap maintains elements in the sorted order.

b)

HashMap is synchronized while ConcurrentHashMap is not synchronized.

c)

HashMap can have one null key and any number of null values whereas ConcurrentHashMap does not allow null keys and null values.

d)

None

39.

Which of the following is a correct difference between ArrayList and Vector?

a)

ArrayList is synchronized while Vector is not.

b)

ArrayList increases its size by doubling the array size while Vector increases by 50% of the array size.

c)

ArrayList is not a legacy class while Vector is the legacy.

d)

None

40.

Which of the following is a correct difference between List and Set?

a)

List maintains no order whereas Set maintains ascending order.

b)

List contain only unique elements whereas Set can contain duplicate elements.

c)

List can hold duplicate elements while Set includes only unique elements.

d)

None

41.

Which of the following is a correct method to convert the array of strings into a list?

a)

Arrays class doList() method

b)

Arrays class asList() method

c)

Arrays class toList() method

d)

None

42.

What is the correct difference between HashMap and TreeMap?

a)

HashMap can contain duplicate elements whereas TreeMap contains only unique elements.

b)

HashMap contains only values whereas TreeMap contains key and values both.

c)

HashMap maintains no order but TreeMap maintains ascending order.

d)

None

43.

Which of the following method you need to override for using an object as key in a HashMap?

a)

hashCode()

b)

hashKey()

c)

hashValue()

d)

equals()

44.

Which of the following is a correct difference between the Iterator and Enumeration?

a)

Iterator is faster than Enumeration.

b)

Enumeration is fail-fast while Iterator is not fail-fast.

c)

Iterator can traverse legacy and non-legacy containers whereas the Enumeration can traverse only legacy containers.

d)

None

45.

Which of the following is not true for a generic collection?

a)

Generic collection is typesafe and checked at compile time.

b)

Generic collection doesn't require typecasting.

c)

Generic collection is not mutable.

d)

None