Javaはマップをリストに変換します

  1. インスタンス
List<BlogComment> blogCommentListResult = new ArrayList<>(blogCommentMap.values());
  1. マップデータはカスタムオブジェクトのリストに変換されます。たとえば、マップのキーと値は、Personオブジェクトの2つの属性に対応します。
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());

上記の3つの方法の違いは、並べ替え処理です

おすすめ

転載: blog.csdn.net/weixin_43088443/article/details/112971066