这是我的代码:
public static HashMap<String, ArrayList<String>> CountryMap = new HashMap<String, ArrayList<String>>();
ArrayList<String> stateInd = new ArrayList<String>();
ArrayList<String> stateUSA = new ArrayList<String>();
stateInd.add("GJ");
stateInd.add("MP");
stateUSA.add("NJ");
stateUSA.add("NY");
CountryMap.put("India",stateInd);
CountryMap.put("USA",stateUSA);
for(int i=0;i<CountryMap.size();i++){
for (Entry<String, ArrayList<String>> entry : CountryMap.entrySet()) {
if (entry.getKey().equals("India") {
ArrayList<String> result = new ArrayList<String>();
# how to add Value of CountryMap with "India" as a Key to result ArrayList??
}
}
}
我想从以“印度”为键的哈希图中向另一个 ArrayList 添加值?
我试过了..
result.add(CountryMap.get("India"));
但它没有奏效。它添加所有值。