javascript arraylist code example

Example 1: java arraylist

import java.util.List; //list abstract class
import java.util.ArrayList; //arraylist class

//Object Lists
List l = new ArrayList();
ArrayList a = new ArrayList();

//Specialized List
List l = new ArrayList();
ArrayList a = new ArrayList();
//only reference data types allowed in brackets <>

//Initial Capacity
List l = new ArrayList(5);
//list will start with a capacity of 5
//saves allocation times

Example 2: arraylist java

//requires either one of these two imports, both work.
import java.util.ArrayList;
//--or--
import java.util.*

ArrayList name = new ArrayList();
//Defining an arraylist, substitute "DataType" with an Object
//such as Integer, Double, String, etc
//the < > is required
//replace "name" with your name for the arraylist

Example 3: arraylist

ArrayListarrayList=new ArrayList<>();

Tags:

Misc Example