When declaring an ArrayList, the datatype stored in the container is specified inside of <>, and the data type must be the name of a class (no primitive data types)
The parameter to the method get represents the index in the ArrayList. The size of the ArrayList is the number of elements contained. If the ArrayList is initially empty, the size is 0.
Passing as argument - a copy of the reference to the instantiated ArrayList is passed to the method. This means that any changes made to the elements inside the method persist outside the method. The one exception to this is if you assign the argument to reference a different ArrayList in memory.
Q14: Put the following code in order to create a program that will declare and instantiate an ArrayList of 10 random values between 1 and 100 and then find the maximum value in the ArrayList.
import java.util.*;
public class main{
public static void main (String[] args) {
---
Random r = new Random();
ArrayList<Integer> list = new ArrayList<>();
---
for (int i = 0; i < 10; i++) {
list.add(r.nextInt(100) + 1);
System.out.println("list["+i+"] is " + list.get(i));
}
---
int max = list.get(0);
---
for (int num: list) {
---
if (num > max)
---
max = num;
---
}
---
System.out.println("Maximum value is " + max);
---
}
}