remove item from array in java
Code snippet on how to remove item from array in java
public static void removeFromArray(ArrayList<Integer> arrList, int item) {
arrList.remove(arrList.indexOf(item));
}
This code is used to remove an item from an ArrayList in Java. It takes two arguments – the ArrayList, which is a collection of elements, and the item that needs to be removed. The code begins by using the remove() method, which takes the index of the item in order to remove it from the ArrayList. Then, the arrList.indexOf(item) statement is used to find the index of the item in the ArrayList, so that it can be removed from it. Finally, the item is removed from the ArrayList.