Answers for "delete data from arraylist in java"

7

How to remove element from arraylist in java

// Java.util.ArrayList.remove(Object) method example
import java.util.ArrayList;
import java.util.List;
public class ArrayListRemoveObjectMethod
{
   public static void main(String[] args)
   {
      List<Integer> al = new ArrayList<>();
      al.add(56);
      al.add(28);
      al.add(39);
      al.add(59);
      al.add(82);
      System.out.println("Before using ArrayList.remove(Object) method size of ArrayList: " + al);
      // removes element 56
      al.remove(new Integer(56));
      // removes element 28
      al.remove(new Integer(28));
      System.out.println("After using ArrayList.remove(Object) method size of ArrayList: " + al);
   }
}
Posted by: Guest on December-01-2020
7

How to remove element from arraylist in java

// Java.util.ArrayList.remove(Object) method example
import java.util.ArrayList;
import java.util.List;
public class ArrayListRemoveObjectMethod
{
   public static void main(String[] args)
   {
      List<Integer> al = new ArrayList<>();
      al.add(56);
      al.add(28);
      al.add(39);
      al.add(59);
      al.add(82);
      System.out.println("Before using ArrayList.remove(Object) method size of ArrayList: " + al);
      // removes element 56
      al.remove(new Integer(56));
      // removes element 28
      al.remove(new Integer(28));
      System.out.println("After using ArrayList.remove(Object) method size of ArrayList: " + al);
   }
}
Posted by: Guest on December-01-2020
-1

arraylist remove value in java

// Given a list of Integers 1, 2, 3, 4, 5, 6 ....etc. remove all values greater than 100.
    public static void main(String[] args) {

ArrayList<Integer>list1=new ArrayList<>(Arrays.asList(1,2,3,50,70,80,120,150,200));
        ArrayList<Integer>list2 = new ArrayList<>();
        for(int each : list1)
            if(each<100)
                list2.add(each);

            list1 = list2;
        System.out.println(list1); // [1, 2, 3, 50, 70, 80]
    }
Posted by: Guest on June-09-2021
-1

arraylist remove value in java

// Given a list of Integers 1, 2, 3, 4, 5, 6 ....etc. remove all values greater than 100.
    public static void main(String[] args) {

ArrayList<Integer>list1=new ArrayList<>(Arrays.asList(1,2,3,50,70,80,120,150,200));
        ArrayList<Integer>list2 = new ArrayList<>();
        for(int each : list1)
            if(each<100)
                list2.add(each);

            list1 = list2;
        System.out.println(list1); // [1, 2, 3, 50, 70, 80]
    }
Posted by: Guest on June-09-2021

Code answers related to "delete data from arraylist in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language