Java converts Map to List

  1. Instance
List<BlogComment> blogCommentListResult = new ArrayList<>(blogCommentMap.values());
  1. Map data is converted into a list of custom objects, for example, the key and value of the map correspond to two attributes of the Person object:
List<Person> list = map.entrySet().stream().sorted(Comparator.comparing(e -> e.getKey()))
		.map(e -> new Person(e.getKey(), e.getValue())).collect(Collectors.toList());

List<Person> list = map.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getValue))
		.map(e -> new Person(e.getKey(), e.getValue())).collect(Collectors.toList());

List<Person> list = map.entrySet().stream().sorted(Map.Entry.comparingByKey())
	.map(e -> new Person(e.getKey(), e.getValue())).collect(Collectors.toList());

The difference between the above three methods is the sorting processing

Guess you like

Origin blog.csdn.net/weixin_43088443/article/details/112971066