jdk8 lambda removeif 实现删除

package com;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class lamber {
public static void main(String[] args) {
List<Map<String,String>> list = new ArrayList<>();
Map<String,String> map = new HashMap<>();
map.put("name", "张三");
list.add(map);
map = new HashMap<>();
map.put("name", "李四");
list.add(map);
map = new HashMap<>();
map.put("name", "王五");
list.add(map);
for(Map<String,String> mapResult:list) {
System.out.println(mapResult.get("name"));
}
System.out.println("---------------------------");
list.removeIf(
li -> li.get("name").equals("张三")
);
for(Map<String,String> mapResult:list) {
System.out.println(mapResult.get("name"));
}
}
}

posted @ 2020-04-16 15:04  再也不见  阅读(3311)  评论(0编辑  收藏  举报