1ArrayList<Integer> list = new ArrayList<Integer>(5);
2int last = list.get(list.size() - 1);
1# The smart way
2
3list = ["first item", "second item", "third item"]
4print(list[len(list) - 1])
5
6# The proper way
7print(list[-1])
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