Chủ Nhật, 3 tháng 6, 2018

Tránh lỗi "ConcurrentModificationException" khi xoá phần tử đang duyệt trong arraylist

https://stackoverflow.com/questions/18448671/how-to-avoid-concurrentmodificationexception-while-removing-elements-from-arr
accepted
Use an Iterator and call remove():
Iterator<String> iter = myArrayList.iterator();

while (iter.hasNext()) {
    String str = iter.next();

    if (someCondition)
        iter.remove();
}

Không có nhận xét nào:

Đăng nhận xét