The .add() method appends an element to the end of the list:
ArrayList<String> colors = new ArrayList<>();
colors.add("red");
colors.add("green");
colors.add("blue");
After these calls, the list contains ["red", "green", "blue"] in that order.
You can also insert at a specific index by passing the index first:
colors.add(1, "yellow");
This shifts "green" and "blue" one position to the right and places "yellow" at index . The list becomes ["red", "yellow", "green", "blue"]. Inserting at an index costs more than appending because Java must shift every element after that position.