1import java.util.ArrayList;
2import java.util.LinkedList;
3import java.util.List;
4
5class scratch{
6 public static void main(String[] args) {
7 List<Integer> aList = new ArrayList<>();
8 List<Integer> lList = new LinkedList<>();
9 }
10}
1//Creating arraylist example
2ArrayList<String> list = new ArrayList<String>();
3
4//Adding objects in arraylist
5list.add("Mango");
6list.add("Banana");
7
8//Change the element (index,"new value")
9list.set(1,"Dates");
10
11//Return the 2nd element, because index starts from 0
12System.out.println("Returning element: " + list.get(1));
1
2for(int i = 0; i < models.size(); i++) {
3 System.out.println(models.get(i).getName());
4