[英]retrieving certain values from ArrayList<HashMap<String, String>>
i have this arrayalist: 我有这个数组主义者:
ArrayList<HashMap<String, String>> contactListad
it contains: 它包含:
[{emailAddress=samir, lastName=samir, contactId=4, phoneNumber=6449494, firstName=samir, homeAddress=paris}, {emailAddress=, lastName=, contactId=6, phoneNumber=, firstName=Rashad, homeAddress=las vegas}, {emailAddress=, lastName=, contactId=9, phoneNumber=, firstName=joe, homeAddress=paris}]
My question iy ifs how can i get the values and store them in another arraylist i want to specify to store only the values having a certain homeAddress equals paris for example. 我的问题是,如果我如何获取这些值并将其存储在另一个我想指定仅存储具有特定homeAddress等于巴黎的值的数组列表中。 i hope my question is clear enough 我希望我的问题很清楚
for example if i specify the homeAddress to be paris, i want the output to be an arraylist containing 例如,如果我将homeAddress指定为巴黎,我希望输出为包含以下内容的arraylist
[{emailAddress=samir, lastName=samir, contactId=4, phoneNumber=6449494, firstName=samir,
homeAddress=paris},{emailAddress=, lastName=, contactId=9, phoneNumber=, firstName=joe,
homeAddress=paris}]
so without the hasmap that has homeAddress equals las vegas 因此,如果没有具有homeAddress的hasmap等于拉斯维加斯
Thank you 谢谢
List<HashMap<String,String>> newArray = new ArrayList<HashMap<String, String>>();
for(HashMap<String, String> hm : contactListad){
String val = hm.get("homeAddress");
if("paris".equals(val)){
newArray.add(hm);
}
}
now you have what you want in newArray
现在您在newArray
拥有了想要的东西
for(HashMap<String, String> hashMap : contactListad) {
String homeAdress = hashMap.get("homeAdress");
if (homeAdress.equals("Paris")) {
//write your code here
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.