1import java.util.ArrayList;
2public class ArrayListExample
3{
4 public static void main(String[] args)
5 {
6 int num = 14;
7 // declaring ArrayList with initial size num
8 ArrayList<Integer> al = new ArrayList<Integer>(num);
9 // append new element at the end of list
10 for(int a = 1; a <= num; a++)
11 {
12 al.add(a);
13 }
14 System.out.println(al);
15 // remove element at index 7
16 al.remove(7);
17 // print ArrayList after deletion
18 System.out.println(al);
19 // print elements one by one
20 for(int a = 0; a < al.size(); a++)
21 {
22 System.out.print(al.get(a) + " ");
23 }
24 }
25}
1import java.util.List; //list abstract class
2import java.util.ArrayList; //arraylist class
3
4//Object Lists
5List l = new ArrayList();
6ArrayList a = new ArrayList();
7
8//Specialized List
9List<String> l = new ArrayList<String>();
10ArrayList<Integer> a = new ArrayList<Integer>();
11//only reference data types allowed in brackets <>
12
13//Initial Capacity
14List<Double> l = new ArrayList<Double>(5);
15//list will start with a capacity of 5
16//saves allocation times
1ArrayList<String> languages = new ArrayList<String>();
2languages.add("PHP");
3languages.add("JAVA");
4languages.add("C#");
5ArrayList<int> numbers = new ArrayList<int>();
6numbers.add(9);
7numbers.add(14);
8numbers.add(2);
1import java.util.ArrayList;
2//create ArrayList
3ArrayList<String> arrayList = new ArrayList<String>();
1List<String> expenseTypeList = new ArrayList<>();
2 expenseTypeList.add("GENERAL");
3 expenseTypeList.add("PURCHASE");
4 expenseTypeList.add("PROJECT");