我有这个传教士:
ArrayList<HashMap<String, String>> contactListad
它包含:
[{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}]
我的问题是,如果我如何获取值并将它们存储在另一个arraylist中我想指定只存储具有某个homeAddress的值等于paris。 我希望我的问题很清楚
例如,如果我指定homeAddress为paris,我希望输出为包含
的arraylist[{emailAddress=samir, lastName=samir, contactId=4, phoneNumber=6449494, firstName=samir,
homeAddress=paris},{emailAddress=, lastName=, contactId=9, phoneNumber=, firstName=joe,
homeAddress=paris}]
所以没有hasmap的homeAddress等于拉斯维加斯
谢谢
答案 0 :(得分:4)
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);
}
}
现在你在newArray
答案 1 :(得分:0)
for(HashMap<String, String> hashMap : contactListad) {
String homeAdress = hashMap.get("homeAdress");
if (homeAdress.equals("Paris")) {
//write your code here
}
}