ArrayList<Integer> integerArray = new ArrayList<Integer>();
ArrayList<String> stringArray = new ArrayList<String>();
ArrayList<Double> doubleArray = new ArrayList<Double>();
//... keep replacing what is inside the <> with the appropriate
//data type
ArrayList<E> yourArray = new ArrayList<E>();
//'E' can be raplaced with any data type or object, or left as
// E if used for general funcitonality
ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
ArrayList<Type> arrayList= new ArrayList<>();
// welcome to softhunt.net
import java.util.ArrayList;
class Main {
public static void main(String[] args){
// create ArrayList
ArrayList<String> Websites = new ArrayList<>();
// Add elements to ArrayList
Websites.add("Softhunt.net");
Websites.add("Pythonprogramming.com");
Websites.add("Tutorial.io");
System.out.println("ArrayList: " + Websites);
}
}
ArrayList<Integer> list=new ArrayList<Integer>();
List<List<Individual>> group = new ArrayList<List<Individual>>(4);
import java.util.ArrayList;
public class ArrayLists {
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); // [Volvo, BMW, Ford, Mazda]
System.out.println(cars.isEmpty()); // false
System.out.println(cars.size()); // 4
cars.remove(0); // removes the element at index 0 (i.e. "Volvo")
System.out.println();
System.out.println(cars); // [BMW, Ford, Mazda]
System.out.println(cars.isEmpty()); // false
System.out.println(cars.size()); // 3
cars.remove(1); // removes the element at index 1 (i.e. "Ford")
System.out.println();
System.out.println(cars); // [BMW, Mazda]
cars.add("Mercedes");
System.out.println();
System.out.println(cars); // [BMW, Mazda, Mercedes]
cars.clear();
System.out.println();
System.out.println(cars); // []
System.out.println(cars.isEmpty()); // true
System.out.println(cars.size()); // 0
}
}