2015년 12월 9일 수요일

[java]ArrayList for문 삭제시 문제점




//for문을 이용하여 삭제하면 동적으로 ArrayList 에 인덱스의 따른 데이터가 변경되므로 Iterator 인터페이스를 이용하여 삭제

        ArrayList<AutoCallServiceVo> mData ...

       AutoCallServiceVo 객체에는 boolean 타입의 isChecked  라는 변수가 존재한다.



public boolean CheckItemDelete(){

boolean result;
//혹시나 모르는 예외 처리..
try{
                        //mData.iterator() 를통해 ArrayList 로 부터 Iteraror 객체를 얻고
                        //for문이나 while 문에서 hasNext() 메소드를 통해
                        //인덱스를 신경 쓰지 않고 접근이 가능하다.

for(Iterator<AutoCallServiceVo> itr = mData.iterator(); itr.hasNext();){

if(itr.next().isChecked){
itr.remove();
}
}

result = true;
notifyDataSetChanged();
}catch(Exception e){
e.printStackTrace();
result = false;
}

return result;
}


댓글 없음:

댓글 쓰기

[lunux]리눅스 폴더별 용량 확인

리눅스 폴더별 용량 확인 조회 하고자 하는 디렉토리 리스트가있는 경로로 이동후 du -h --max-depth=1