[英]Filter Object list with map key value , replace the Map value
I have a List of Objects我有一个对象列表
List<Person> personLst = [{"person:" {personName:AASH_01 , country :AUS, state :ADL, zip :null },
{personName:AASH_01 , country :AUS, state :MLB, zip :null}}]
and Map holds a key value and based on this need to apply the filter for the list.和 Map 持有一个键值,并基于此需要为列表应用过滤器。
Map<String, String> lstMap = new HashMap<>();
lstMap.put("ADL","12345")
Apply Filter Condition: If the personLst.contains(ADL)
this is a map key filter it and replace the zip with map value (12345)
.应用过滤条件:如果
personLst.contains(ADL)
这是一个 map 密钥,过滤它并用 map 值(12345)
替换 zip。
Tried different stackoverflow question, did not help much on.尝试了不同的stackoverflow问题,并没有太大帮助。
Just to be sure,只是要确定,
List<Person> personLst = [{"person:" {personName:AASH_01 , country :AUS, state :ADL, zip :null },{personName:AASH_01 , country :AUS, state :MLB, zip :null}}]
really refers to a list of valid java objects, right?真的是指有效 java 对象的列表,对吧? Because in the current state those would be valid JavaScript Objects, but not valid Java objects.
因为在当前的 state 中,这些将是有效的 JavaScript 对象,但不是有效的 Java 对象。
Also, should a List<Person>
really be called with personLst.contains(String)
?另外,
List<Person>
真的应该用personLst.contains(String)
调用吗?
So, assuming these are valid Java objects with the correct getters and setters, and the correct method is intended, you should be able to use因此,假设这些是具有正确 getter 和 setter 的有效 Java 对象,并且打算使用正确的方法,您应该能够使用
personLst.forEach(p -> {
if(lstMap.containsKey(p.getState()))
p.setZip(lstMap.get(p.getState()));
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.