The ArrayList
class has many useful methods. For example, to add elements to the ArrayList
, use the add()
method:
Example
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<String> cars = new ArrayList<String>();
cars.add("Volvo");
cars.add("BMW");
cars.add("Ford");
cars.add("Mazda");
System.out.println(cars);
}
}
Practice Excercise Practice now