How to Remove List From Arraylist

 We can remove  all element of list from arraylist using removeAll().

import java.util.ArrayList;
import java.util.List;

public class RemoveList {

public static void main(String[] args) {
ArrayList<String> arr = new ArrayList<String>();
// add element in arraylist
arr.add(“c”);
arr.add(“php”);
arr.add(“html”);
arr.add(“java”);
// print arraylist
System.out.println(” berfore remove arrayList is = ” + arr);

List<String> brr = new ArrayList<String>();
brr.add(“php”);
brr.add(“java”);

/*
* Removes from this list all of its elements that are
contained in the specified collection.
*/

arr.removeAll(brr);

System.out.println(“after remove arraylist is = “+arr);

}

}

Output:

berfore remove arrayList is = [c, php, html, java]

after remove arraylist is = [c, html]

 

Related Posts:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

43 − = 35