Quiz about Java Quiz Day 38

Java Quiz Day 38

Last Updated :
Discuss
Comments

Question 1

What is the main characteristic of the Set interface in Java?

  • A

    Maintains insertion order

  • B

    Does not allow duplicate elements

  • C

    Allows duplicate elements

  • D

    Stores elements in key-value pairs

Question 2

Which Set implementation maintains the insertion order of elements?

  • A

    HashSet

  • B

    TreeSet

  • C

    LinkedHashSet

  • D

    SortedSet

Question 3

Which Set implementation sorts elements in natural order?

  • A

    HashSet


  • B

    TreeSet

  • C

    LinkedHashSet

  • D

    EnumSet

Question 4

Which of the following is true about TreeSet in Java?

  • A

    It allows duplicate elements

  • B

    It stores elements in random order

  • C

    It stores elements in sorted order

  • D

    It is an implementation of List

Question 5

What is the default initial capacity of a HashSet in Java?

  • A

    10

  • B

    20

  • C

    5

  • D

    16

Question 6

What is the primary difference between HashSet and TreeSet?

  • A

    HashSet stores elements in a sorted order, while TreeSet does not

  • B

    HashSet allows duplicates, while TreeSet does not

  • C

    HashSet is faster than TreeSet for adding elements

  • D

    HashSet stores elements in an unordered manner, while TreeSet stores elements in sorted order

Question 7

Which of the following collections allows for null elements in Java?

  • TreeSet

  • LinkedHashSet

  • HashSet

  • None of the above

Tags:

There are 7 questions to complete.

Take a part in the ongoing discussion