ArrayList
ArrayList implementation of List interface documentation in java.
import java.util.*;
public class ArrayListDocumentation {
// Main driver method
public static void main(String[] args)
{
// Implementing the list interface as an arraylist
// Note: You can't instantiate an object of the List class.
// The List interface describes a collection and supports things like iteration, or adding/deleting
// ArrayList implements the List
List<String> brands = new ArrayList<String>();
// Adding elements to ArrayList
brands.add("Honda");
brands.add("Toyota");
brands.add("Tesla");
System.out.println("Using the .add method 3 times.");
System.out.println(brands);
System.out.println();
// Using addAll method to add multiple elements to the ArrayList at once
List<String> newBrands = new ArrayList<String>();
newBrands.add("BMW");
newBrands.add("Porsche");
newBrands.add("Nissan");
brands.addAll(newBrands);
System.out.println("Using the .addAll method to add 3 brands.");
System.out.println(brands);
}
}
ArrayListDocumentation.main(null);