Given an array of integers values, return the value of the first element
An array / list is a collection of elements, all of the same type.
int[] list = {1,2,3} creates a list of ints (integers).
String[] list = {"To","be","or","not","to","be"} creates a list of Strings.
The way you access an individual element of a list is by its index / position.
The syntax is:
(a) the name of the list variable followed by
(b) the index number inside of square brackets.
For example:
nums[0] is the 1st element of the array variable int[] nums.
list[1] is the 2nd element of the array variable int[] list.
words[2] is the 3rd element of the array variable String[] words.
As with Strings, you can use expressions instead of hard-coded numbers.
For example:
int[] values;
int len = values.length; // NOTE: no parentheses after length values[len-1] is the last element in values values[len-2] is the 2nd-to-last element in values
public int getFirstElement(int[] list) {
int first = list[0];
return first;
}