我想计算两个哈希图的键的并集。我写了以下代码(下面是MWE),但我
得到 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);
}
}