Answers for "arraylist remove in java"

2

ArrayList removeIf() method in java

import java.util.ArrayList;
public class ArrayListRemoveIfMethodExample
{
   public static void main(String[] args)
   {
      ArrayList<Integer> al = new ArrayList<Integer>();
      al.add(15);
      al.add(8);
      al.add(58);
      al.add(19);
      // remove numbers divisible by 2
      al.removeIf(n -> (n % 2 == 0));
      // print list
      for(int a : al)
      {
         System.out.println(a);
      }
   }
}
Posted by: Guest on October-29-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
5

java arraylist remove

//create ArrayList
ArrayList<String> arrayList = new ArrayList<String>();
//add item to ArrayList
arrayList.add("item");
//check if ArrayList contains item (returns boolean)
System.out.println(arrayList.contains("item"));
//remove item from ArrayList
arrayList.remove("item");
Posted by: Guest on July-22-2020
0

arraylist remove name in java

public static void main(String[] args) {

ArrayList<String> names = new ArrayList<>(Arrays.asList("Ahmed", "John", "Eric", "Ahmed"));
    names.removeAll( Arrays.asList("Ahmed"));
    System.out.println(names); // [John, Eric]
Posted by: Guest on June-09-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language