Java Collections Quiz-2

Java Collections Quiz-2 | In Java, collection framework classes are used to store elements in value or key-value format without size limitation. We have listed some basic and fundamental Java Collections Quiz, answer them. Previously we have seen:- Java Collections Quiz-1

Also see- Java Collection Framework OverviewJava Collection InterfaceList Interface in Java

Q1) Which of the following classes are direct/indirect implementation classes of the List interface?

a) ArrayList, LinkedList, Vector, and Stack
b) ArrayList and LinkedList
c) ArrayList, LinkedList, and Vector
d) None of these

View Answer Answer:- a) ArrayList, LinkedList, Vector, and Stack

Q2) Vector and Stack classes were introduced in?

a) 1.0 Version
b) 1.2 Version
c) 1.5 Version
d) 1.8 Version

View Answer Answer:- a) 1.0 Version

The Vector and Stack classes were introduced in Java 1.0 Version therefore they are also called legacy classes.

Q3) Which of the following options are true about the List interface and its implementation classes?

a) Duplicates are allowed.
b) Insertion order will be preserved.
c) Null insertion is allowed.
d) All of these.

View Answer Answer:- d) All of these.

In List and its implementation classes, duplicates are allowed & insertion orders must be preserved. They can store null values.

Q4) Vector and Stack classes are?

a) Thread-safe classes
b) Non-Thread-safe classes
c) Both
d) None of these

View Answer Answer:- a) Thread-safe classes

The Vector and Stack classes were introduced in the 1.0 version and they are introduced as Thread-safe classes. It means all the methods of these classes are declared as synchronized. Therefore, for every method call on these class objects, JVM locks and unlocks the object.

Q5) ArrayList and LinkedList classes are?

a) Thread-safe classes
b) Non-Thread-safe classes
c) Both
d) None of these

View Answer Answer:- b) Non-Thread-safe classes

ArrayList and LinkedList classes are non-thread-safe classes, it means all the methods of these classes are non-synchronized methods.

Q6) Which of the following classes are implementation classes/interfaces of the Set interface?

a) HashSet, and LinkedHashSet
b) NavigableSet, and TreeSet
c) HashSet, LinkedHashSet, NavigableSet, and TreeSet
d) HashSet, LinkedHashSet, SortedSet, NavigableSet, and TreeSet

View Answer Answer:- d) HashSet, LinkedHashSet, SortedSet, NavigableSet, and TreeSet

Q7) SortedSet and NavigableSet are an interface or class?

a) interface
b) class
c) abstract class
d) Enum

View Answer Answer:- a) interface

Q8) Which of the following statements are valid about the Set interface and its implementation classes?

  1. Duplicates are allowed.
  2. Duplicates are not allowed.
  3. Insertion order preserved.
  4. Insertion order not preserved.

a) 1 & 3
b) 1 & 4
c) 2 & 3
d) 2 & 4

View Answer Answer:- d) 2 & 4

In the Set interface and its implementation classes, duplicates are not allowed & insertion order is not preserved.

Q9) Which of the following statements are true about SortedSet(I)?

a) Duplicates are not allowed.
b) Insertion order is not preserved.
c) Elements are inserted according to some sorting order.
d) All of these

View Answer Answer:- d) All of these

The SortedSet(I) implements Set(I). The Set(I) doesn’t allow duplicate values, and the insertion order is not preserved. If we want to insert elements according to some sorting order then SortedSet(I) can be used.

Q10) By default Queue(I) follows?

a) FIFO (First in First out)
b) LIFO (Last in First out)
c) Both
d) None of these

View Answer Answer:- a) FIFO (First in First out)

Usually, the queue follows FIFO (first in first out) order but based on our requirement we can implement our own priority order also.

Q11) Map(I) implements Collection(I)?

a) True
b) False
c) None of these

View Answer Answer:- b) False

Map(I) doesn’t implements Collection(I).

Q12) Which of the following statements are true about Map(I) and its subclasses?

a) Both key and value must be numbers.
b) Key should be number, and Value must be String.
c) Both key and value must be String.
d) Both key and value should be Objects.

View Answer Answer:- d) Both key and value should be Object.

Both key & values are objects. Hence key can be number, String, and e.t.c. Similarly, the value also can be number, string, and e.t.c.

Q13) Which of the following statements are true about Map(I) and its subclasses?

a) Key can’t be duplicated.
b) Value can’t be duplicated.
c) Both keys & values can’t be duplicated.
d) Duplicate is allowed for both key & value.

View Answer Answer:- a) Key can’t be duplicated.

In Map, Duplicate keys are not allowed but values can be duplicated.

Q14) If we want to represent a group of key-value pairs according to some sorting order of keys then we should go for?

a) Hashtable
b) SortedMap
c) HashMap
d) None of these

View Answer Answer:- b) SortedMap

If we want to represent a group of key-value pairs according to some sorting order of keys then we should go for SortedMap.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *