what is arraylist code example
Example 1: how to import an arraylist in java
import java.util.ArrayList;
Example 2: integer arraylist
ArrayList<Integer> contractValue = new ArrayList<Integer>();
Example 3: what is arraylist
Size is dynamic
Only supports objects
not syncronized
array based class
Example 4: 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<String> l = new ArrayList<String>();
ArrayList<Integer> a = new ArrayList<Integer>();
//only reference data types allowed in brackets <>
//Initial Capacity
List<Double> l = new ArrayList<Double>(5);
//list will start with a capacity of 5
//saves allocation times
Example 5: arraylist java methds
import java.util.ArrayList;
ArrayList<Integer> myList = new ArrayList<Integer>();
myList.add(0);
myList.remove(0);//Remove at index 0
myList.size();
myList.get(0);//Return element at index 0
Example 6: arraylist in java
Size is dynamic
Only supports objects
not syncronized
array based class