1ArrayList<Integer> list = new ArrayList<Integer>(5);
2int last = list.get(list.size() - 1);
1int [] numbers = {1, 2, 3, 4, 5};
2
3firstElement = numbers[0];
4lastElement = numbers[numbers.length-1];
1int[] someArray = {1,2,3,4,5};
2int first = someArray[0];
3int last = someArray[someArray.length - 1];
4System.out.println("First: " + first + "\n" + "Last: " + last);
1int[] arr = new int[5]; //length of the array is 5
2int val = arr[arr.length - 1]; //here variable val stores the last element of arr