A

Admin • 828.03K Points
Coach

Q. Which of the following will throw NullPointerException?

  • (A) new HashSet<>().add(null)
  • (B) new TreeSet<>().add(null)
  • (C) new LinkedHashSet<>().add(null)
  • (D) new ArrayList<>().add(null)
  • Correct Answer - Option(B)
  • Views: 11
  • Filed under category Java
  • Hashtags: Java Set

Explanation by: Admin
TreeSet does not allow null if a comparator or natural ordering is used.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.