Delete elements from a list.
import
public |
The remove() method deletes an item from the list by position or value. If a position is specified, it returns the removed item. If a value is specified, it returns true if the item was found and removed, otherwise false.
If a value is specified and multiple elements in the list share the same value, only the first occurrence is deleted.
When dealing with a list of integers and you want to remove an integer by its value, you must pass an Integer object. Refer to the examples below for more details.
One of the following options:
public |
public |
T denotes the data type of the elements in the list.
Parameter |
Description |
index |
Required: The index of the item to be deleted. |
item |
Required: The value of the item to be deleted. |
Returns: |
If an object is passed as an argument, it returns true if the object is found in the list and false otherwise. If an index is passed, it returns the object that was removed. |
Throws: |
IndexOutOfBoundsException occurs if the index is negative, equal to the list’s size, or exceeds the list’s size. |
Delete an integer from the list either by position or by value.
import public
|