Herman Nz
0
Q:

arraylist remove method 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);
      }
   }
}
2
//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");
4
//Create the ArrayList
List<Integer> al = new ArrayList<>(); 
//Add the items
al.add(10);
al.add(18);
//Remove item(1 = 2nd item in list)
al.remove(1); 
>> [10]
4
public E remove(int index)	// returns removed element at index
0

New to Communities?

Join the community