Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 484 Bytes

add_an_item.md

File metadata and controls

23 lines (17 loc) · 484 Bytes

Add an item

To add an item to an ArrayList you use the .add method.

import java.util.ArrayList;

void main() {
    ArrayList<String> names = new ArrayList<>();
    names.add("The Bowery King");
    names.add("Caine");

    System.out.println(names);
}

The way this works is conceptually the same as the growable array that we went over earlier.

All you need to know though is that you can add as many items as you will and the container will grow dynamically.