Append an item to a list.
import public |
The add() method appends an item to the list.
If an index is specified, the new item will be inserted at that position, shifting all subsequent elements in the list one position forward.
If no index is specified, the new item will be added to the end of the list.
Choose one of the following:
public |
public |
T represents the data type of the items in the list.
Parameter |
Description |
index |
Optional: The position in the list where the item should be added. |
item |
Required: The item that will be added to the list. |
Returns: |
If an index is specified, the method returns nothing. When no index is specified, it returns true if the list is altered and false if the list remains unchanged. |
Throws |
IndexOutOfBoundsException occurs if the index is negative or exceeds the list’s size. |
Insert an item at a specific position within the list.
import public
|