public static void main(String[] args) {
Set<String> set = new HashSet<String>();
set.add("a");
set.add("b");
set.add("c");
set.add("d");
Iterator<String> iter = set.iterator();
while (iter.hasNext()) {
String s = iter.next();
if ("a".equals(s)) {
iter.remove();
}
}
System.out.println(set);
Set<Integer> set1 = new HashSet<Integer>();
set1.add(1);
set1.add(2);
set1.add(3);
set1.add(4);
Iterator<Integer> iter1 = set1.iterator();
while (iter1.hasNext()) {
int s = iter1.next();
if (3 == s) {
iter1.remove();//big error
}
}
System.out.println(set1);
}
java set 删除元素 java.util.ConcurrentModificationException
最新推荐文章于 2023-01-17 14:09:29 发布