자바/자바팁
java list 안전하게 제거
행복한 수지아빠
2017. 2. 10. 19:38
반응형
List<String> list = new ArrayList<>();
Iterator<String> iterator = list.iterator(); // while (iterator.hasNext()) {
for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
String string = iterator.next();
if (string.isEmpty()) {
// Remove the current element from the iterator and the list.
iterator.remove(); }
}
반응형