last element of list in java code example
Example 1: how to find last element of list
L=[1,2,3,4,5]
lastElement=L[L.size()]
Example 2: get last n elements from list java
List<E> tail = l.subList(Math.max(l.size() - 3, 0), l.size());
L=[1,2,3,4,5]
lastElement=L[L.size()]
List<E> tail = l.subList(Math.max(l.size() - 3, 0), l.size());