Substitute an item in a list.
import public |
The set() method replaces an item at a specified position in the list and returns the item previously at that position.
public |
T denotes the data type of the items in the list.
Parameter |
Description |
index |
Required: The index of the item to be replaced. |
item |
Required: The new item to be inserted at the specified position. |
Returns: |
The item that was previously located at the specified position in the list. |
Throws: |
IndexOutOfBoundsException occurs if the index is negative, equal to the list’s size, or greater than the list’s size. |