Java 8 NullPointerException in Collectors.toMap
问题 The Java 8 Collectors.toMap throws a NullPointerException if one of the values is \'null\'. I don\'t understand this behaviour, maps can contain null pointers as value without any problems. Is there a good reason why values cannot be null for Collectors.toMap ? Also, is there a nice Java 8 way of fixing this, or should I revert to plain old for loop? An example of my problem: import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; class