Java Quiz Day 40

Last Updated :
Discuss
Comments

Question 1

Which method of HashMap is used to check if a key exists?

  • A

    containsKey()


  • B

    hasKey()

  • C

    keyExists()

  • D

    isKey()

Question 2

Which of the following is true about LinkedHashMap in Java?

  • A

    It does not maintain the insertion order

  • B

    It allows only unique values

  • C

    It maintains the insertion order

  • D

    It is slower than HashMap in terms of performance

Question 3

What is the time complexity of the get() method in a HashMap?

  • A

    O(log n)

  • B

    O(n)

  • C

    O(1)


  • D

    O(n^2)

Question 4

What does the TreeMap store in Java?

  • A

    Elements in random order

  • B

    Key-value pairs in ascending order of keys

  • C

    Only the keys, sorted

  • D

    Only the values, sorted

Question 5

Which of the following does NOT allow null keys in Java?

  • A

    HashMap

  • B

    TreeMap

  • C

    LinkedHashMap

  • D

    None of the above

Question 6

Which of the following is true about HashMap in Java?

  • A

    It does not maintain any order of keys

  • B

    It does not allow duplicate keys

  • C

    It allows null values and null keys

  • D

    All of the above

Question 7

Which Map implementation maintains the insertion order of keys?

  • A

    HashMap

  • B

    TreeMap

  • C

    LinkedHashMap

  • D

    EnumMap

Question 8

What happens when you insert a new entry with a key that already exists in a HashMap?

  • A

    The map throws an exception

  • B

    The existing value is replaced

  • C

    Both values are stored

  • D

    The new value is ignored

Question 9

Which Map implementation stores keys in sorted (natural) order?

  • A

    HashMap

  • B

    TreeMap

  • C

    LinkedHashMap

  • D

    IdentityHashMap

Question 10

Which of the following allows one null key and multiple null values?

  • A

    HashMap


  • B

    TreeMap

  • C

    LinkedHashMap

  • D

    Both a and c

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion