xxxxxxxxxx
ArrayList<Integer> list = new ArrayList<Integer>(5);
int last = list.get(list.size() - 1);
xxxxxxxxxx
int[] arr = new int[5]; //length of the array is 5
int val = arr[arr.length - 1]; //here variable val stores the last element of arr
xxxxxxxxxx
# The smart way
list = ["first item", "second item", "third item"]
print(list[len(list) - 1])
# The proper way
print(list[-1])
xxxxxxxxxx
lst = [2, 5 , 6, 3, 8, 9]
n = len(lst) #get the length
last_el = lst[n-1] #get the last element
print("The last element of the list is:", last_el)