how to remove an item from a list in java code example
Example 1: How to remove element from arraylist in java
import java.util.ArrayList;
import java.util.List;
public class ArrayListRemoveIndex
{
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(int index) method: " + al);
al.remove(1);
al.remove(1);
System.out.println("After using ArrayList.remove(int index) method: " + al);
}
}
Example 2: java list remove
List<String> list = new ArrayList<>();
list.remove(key);
Example 3: how to remove an element from an arraylist java
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);
al.remove(1);
al.remove(1);
System.out.println("Modified ArrayList : " + al);
}
}