java 遍历集合的同时添加和删除元素

xiaoxiao2021-02-28  121

ListIterator<Integer> iterator = vector.listIterator(); while (iterator.hasNext()) { Integer next = iterator.next(); if (next == 5) { iterator.remove(); } if (next == 10) { iterator.add(22); } System.out.println(next); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } iterator = vector.listIterator(); while (iterator.hasNext()) { Integer next = iterator.next(); System.out.println(next); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } }
转载请注明原文地址: https://www.6miu.com/read-38757.html

最新回复(0)