IT노트(구)/Java
ArrayList를 ArrayList 기준으로 삭제하는 방법[removeAll() 이용]
스프링연구소
2016. 1. 6. 22:17
ArrayList에서 특정 데이터를 삭제하고 싶다면(ArrayList를 ArrayList로 지우고 싶다면)
removeAll()을 사용할 수 있다.(내용이 String인 경우 가장 강력하다!)
예제는 다음과 같다!
ArrayList list = new ArrayList();
list.add("a");
list.add("b");
list.add("c");
list.add("d");
list.add("e");
System.out.println(list); // [a, b, c, d, e]가 출력된다.
ArrayList list2 = new ArrayList();
list2.add("d");
list2.add("e");
list.removeAll(list2); // d, e를 빼버린다.
System.out.println(list); // [a, b, c]가 출력된다.
removeAll()을 사용할 수 있다.(내용이 String인 경우 가장 강력하다!)
예제는 다음과 같다!
ArrayList
list.add("a");
list.add("b");
list.add("c");
list.add("d");
list.add("e");
System.out.println(list); // [a, b, c, d, e]가 출력된다.
ArrayList
list2.add("d");
list2.add("e");
list.removeAll(list2); // d, e를 빼버린다.
System.out.println(list); // [a, b, c]가 출력된다.