我想計算兩個hashmaps的鍵的聯合。我寫了下面的代碼(下面的MWE),但我用Java計算兩個HashMap的keySet的聯合
得到UnsupportedOperationException。完成這個有什麼好處?
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class AddAll {
public static void main(String args[]){
Map<String, Integer> first = new HashMap<String, Integer>();
Map<String, Integer> second = new HashMap<String, Integer>();
first.put("First", 1);
second.put("Second", 2);
Set<String> one = first.keySet();
Set<String> two = second.keySet();
Set<String> union = one;
union.addAll(two);
System.out.println(union);
}
}
謝謝大家的支持數據。這是豐富的,正是我所需要的。 – 2013-02-15 00:34:21