Because Collectors.toMap(key, value) is by default designed to throw NPE if any value is null. This happens due its internal logic( Map**.merge()** ) where it tries to match (key, value) but it crashes if it encounters 'null' value. Although HashMap allows null values, Collectors.toMap() will not allow null and it will throw NullPointerException. We can handle using custom map supplier or merge functions