从list集合中找某个map

List<Map<String, Object>> list = new ArrayList<>();
Map<String, Object> map1 = new HashMap<>();
map1.put("name", "苹果");
map1.put("code", "apple");
list.add(map1);
Map<String, Object> map2 = new HashMap<>();
map2.put("name", "橙子");
map2.put("code", "orange");
list.add(map2);
//从list中查找code为apple的map
Map<String, Object> resultMap = list.stream().filter(map -> "apple".equals(map.get("code"))).findFirst().orElse(null);

 

posted @ 2024-04-15 14:29  一隅桥畔  阅读(27)  评论(0编辑  收藏  举报