Question: why null is not allowed in treemap?
Answer: Null Keys and Null Values TreeMap sorts elements in natural order and doesn't allow null keys because compareTo() method throws NullPointerException if compared with null. So if we try to run the next code: TreeMap<String, Integer> treeMap = new TreeMap<>(); treeMap.