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]
Storing Java Object In ArrayList
How to count number of element in ArrayList
How to insert element in arraylist
How to use retailAll in arraylist
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:
How to count number of element in ArrayList
How to insert element in arraylist
How to use retailAll in arraylist
No comments:
Post a Comment