JDK8 Lamdba expression into a Map, value is null problem

// convert the list to a Type Map 
Map <String, String> = map list.stream () the collect (Collectors.toMap (the Person :: getId, the Person :: getName));. 
@ If the value in the packet null pointer map abnormal, the need value, i.e. toMap () determines a second parameter logically empty (null) values; example: change Person :: getName i.e. p -> p.getName () == null "? ": p.getName () can solve the problem value is null // <the Person, String, String> Collector <the Person,, the Map <String, String >> java.util.stream.Collectors.toMap (Function <Super?? the Person,? the extends String> keymapper, Function <? Super the Person,? the extends String> valueMapper, BinaryOperator <String> mergeFunction) // toMap () third argument is that when there are duplicate Key, performs this logic, biography the two parameters, the first parameter is the value of the Map has value exists, the second is the value of the value of the upcoming cover, which ultimately returns whichever

 

Guess you like

Origin www.cnblogs.com/XingXiaoMeng/p/10939512.html