HashMap allows null keys by storing them in a special bucket without calling hashCode(), while TreeMap throws NullPointerException because it requires key comparison for maintaining sorted order. TreeMap can accept null keys with a custom Comparator that handles null values. Both maps allow only one null key, which gets

4m read timeFrom medium.com
Post cover image

Sort: