public void calDateBetweenAandB() import java.util.Arrays; import java.util.List; public class ListLastElement { public static void main(String[] argv){ List<String> list = Arrays.asList( "A", "B", "C", "D" ); String lastElement = null; if( !list.isEmpty() ) lastElement = list.get(list.size() - 1); System.out.print( "The last element is " + lastElement); } }
list.get(list.size() - 1)
The last element is D