Answers for "removeall arraylist java"

2

ArrayList removeAll(Collection c) method in java

import java.util.ArrayList;
public class ArrayListRemoveAllExample
{
   public static void main(String[] args)
   {
      try
      {
         ArrayList<Integer> al1 = new ArrayList<Integer>();
         al1.add(2);
         al1.add(4);
         al1.add(6);
         al1.add(8);
         al1.add(10);
         System.out.println("ArrayList before using removeAll() method: " + al1);
         // create another ArrayList
         ArrayList<Integer> al2 = new ArrayList<Integer>();
         al2.add(2);
         al2.add(4);
         al2.add(6);
         // print al2
         System.out.println("Elements to be removed: " + al2);
         // remove elements from ArrayList using removeAll() method
         al1.removeAll(al2);
         // print al1
         System.out.println("ArrayList after using removeAll() method: " + al1);
      }
      catch(NullPointerException ex)
      {
         System.out.println("Exception: " + ex);
      }
   }
}
Posted by: Guest on October-30-2020
2

ArrayList removeAll(Collection c) method in java

import java.util.ArrayList;
public class ArrayListRemoveAllExample
{
   public static void main(String[] args)
   {
      try
      {
         ArrayList<Integer> al1 = new ArrayList<Integer>();
         al1.add(2);
         al1.add(4);
         al1.add(6);
         al1.add(8);
         al1.add(10);
         System.out.println("ArrayList before using removeAll() method: " + al1);
         // create another ArrayList
         ArrayList<Integer> al2 = new ArrayList<Integer>();
         al2.add(2);
         al2.add(4);
         al2.add(6);
         // print al2
         System.out.println("Elements to be removed: " + al2);
         // remove elements from ArrayList using removeAll() method
         al1.removeAll(al2);
         // print al1
         System.out.println("ArrayList after using removeAll() method: " + al1);
      }
      catch(NullPointerException ex)
      {
         System.out.println("Exception: " + ex);
      }
   }
}
Posted by: Guest on October-30-2020
0

how to remove an element from an arraylist java

// Java program to demonstrate working of remove 
// on an integer arraylist 
import java.util.List; 
import java.util.ArrayList; 
  
public class GFG 
{ 
    public static void main(String[] args) 
    { 
        List<Integer> al = new ArrayList<>(); 
        al.add(10); 
        al.add(30); 
        al.add(1); 
        al.add(2); 
  
        // This makes a call to remove(int) and  
        // removes element 20. 
        al.remove(1); 
          
        // Now element 30 is moved one position back 
        // So element 30 is removed this time 
        al.remove(1); 
  
        System.out.println("Modified ArrayList : " + al); 
    } 
}
Posted by: Guest on January-14-2021
0

how to remove an element from an arraylist java

// Java program to demonstrate working of remove 
// on an integer arraylist 
import java.util.List; 
import java.util.ArrayList; 
  
public class GFG 
{ 
    public static void main(String[] args) 
    { 
        List<Integer> al = new ArrayList<>(); 
        al.add(10); 
        al.add(30); 
        al.add(1); 
        al.add(2); 
  
        // This makes a call to remove(int) and  
        // removes element 20. 
        al.remove(1); 
          
        // Now element 30 is moved one position back 
        // So element 30 is removed this time 
        al.remove(1); 
  
        System.out.println("Modified ArrayList : " + al); 
    } 
}
Posted by: Guest on January-14-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language