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"));
}
}
}