关于Set的java.lang.UnsupportedOperationException

版权声明:本文为博主原创文章。 https://blog.csdn.net/qq_36691683/article/details/88429555

Map的keySet()方法返回的Set对象是不支持addAll()方法的,否则就会产生UnsupportedOperationException

如何解决:

Map map =new HashMap();
map.put("key", "value");
Map map1 =new HashMap();
map1.put("key", "value");

Set set=new HashSet();
set.addAll(map.keySet());
set.addAll(map1.keySet());

猜你喜欢

转载自blog.csdn.net/qq_36691683/article/details/88429555
今日推荐