Created
August 16, 2018 06:58
-
-
Save duqicauc/669657535a9d6af970e3c9f4f4f5ab06 to your computer and use it in GitHub Desktop.
List转换成Map,以List里元素的某个字段未key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class List2MapExample { | |
public static void main(String[] args) { | |
List<ClassRecordDTO> list = new ArrayList<>(); | |
list.add(new ClassRecordDTO(1, 2, "xxx", 0.0, 0.0)); | |
list.add(new ClassRecordDTO(1, 2, "yyy", 0.0, 0.0)); | |
list.add(new ClassRecordDTO(2, 3, "zzz", 0.0, 0.0)); | |
Map<String, ClassRecordDTO> result = list.stream().collect(Collectors.toMap(ClassRecordDTO::getClassName, classRecordDTO -> classRecordDTO)); | |
System.out.println(result.size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment