Development/Java
java - ArrayList removeAll 메소드 이용한 값 삭제
linuxism
2012. 9. 4. 14:07
ArrayList removeAll 메소드를 이용해서 삭제할 값들이 들어 있는 ArrayList를 넘겨주면 값들을 비교해서 같은 값은 삭제를 합니다.
아래 코드는 a b c d를 가진 ArrayList에 removeAll 메소드를 이용해서 b d를 가진 ArrayList를 넘겨 주어서 b d를 삭제한 샘플 입니다.
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
System.out.println(list);
List<String> list2 = new ArrayList<String>();
list2.add("b");
list2.add("d");
list.removeAll(list2);
System.out.println(list);
}
출력 결과는 아래와 같습니다.
[a, b, c, d]
[a, c]
출처 - http://k.daum.net/qna/openknowledge/view.html?qid=40E7M