java append item to arraylist code example
Example 1: arraylist insert at position
import java.util.ArrayList;
public class main{
public static void main(String[] args){
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(0);
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
list.add(0, 100);
for(int element : list){
System.out.print(list + ", ");
}
}
}
Example 2: java arraylist add
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("item");
System.out.println(arrayList.contains("item"));
arrayList.remove("item");