HashMap allows storing at most one null key and many null values. However, TreeMap doesn’t allow a null key but may contain many null values . If we’re using a TreeMap with a user-defined Comparator, then it depends on the implementation of the compare() method how null values get handled.9 Nis 2020