从列表<;地图<;字符串,对象>&燃气轮机;要删除java 8中HashMap中某个属性的重复值,
附加代码段从列表<;地图<;字符串,对象>&燃气轮机;要删除java 8中HashMap中某个属性的重复值,,java,Java,附加代码段 List<Map<String,A>> listm=new ArrayList<>(); Map<String,A> map=new HashMap<>(); A a1=new A(); a1.setAge("30"); a1.setName("Mani"); map.put("1", a1); A a2 =new A(); a2.setAge("31"); a2.setName("sasi"); Map<Stri
List<Map<String,A>> listm=new ArrayList<>();
Map<String,A> map=new HashMap<>();
A a1=new A();
a1.setAge("30");
a1.setName("Mani");
map.put("1", a1);
A a2 =new A();
a2.setAge("31");
a2.setName("sasi");
Map<String,A> map1=new HashMap<>();
map1.put("2", a2);
A a3=new A();
a3.setAge("31");
a3.setName("Naveen");
Map<String,A> map2=new HashMap<>();
map2.put("3", a3);
listm.add(map);
listm.add(map1);
listm.add(map2);
List<Map<String, A>> list = listH.stream()
.collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting()))
.entrySet()
.stream()
.filter(e -> e.getValue() == 1)
.map(Map.Entry::getKey)
.collect(Collectors.toList());
List listm=new ArrayList();
Map Map=newhashmap();
a1=新的A();
a1.设置(“30”);
a1.设置名称(“Mani”);
地图放置位置(“1”,a1);
a2=新的A();
a2.设置(“31”);
a2.设置名称(“sasi”);
Map map1=新的HashMap();
地图1.放置(“2”,a2);
a3=新的A();
a3.设置(“31”);
a3.设置名称(“Naveen”);
Map map2=新的HashMap();
地图2.放置(“3”,a3);
添加(映射);
列表M.add(地图1);
列表m.add(map2);
List=listH.stream()
.collect(Collectors.groupingBy(Function.identity(),LinkedHashMap::new,Collectors.counting())
.entrySet()
.stream()
.filter(e->e.getValue()==1)
.map(map.Entry::getKey)
.collect(Collectors.toList());
上面的lambda表达式没有删除重复的年龄对象,响应应该只有2条记录。其中一个是组30和组31,因为组31是重复的更改参数过滤打开:
.filter(entry-> Collections.frequency(listH.values(), entry.getValue()) > 1)
此代码未编译-什么是
listH
?为什么有Map
s的List
?每个Map
只有一个条目。