Java tutorial
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.util.Collection; import java.util.List; public class Main { public static <T> T getLastOrNull(List<T> l) { final int size = l.size(); if (size == 0) return null; return l.get(size - 1); } /** * @param coll * @postcondition (coll == null) --> (result == 0) * @postcondition (coll != null) --> (result == coll.size()) */ public static int size(Collection<?> coll) { return (coll == null) ? 0 : coll.size(); } }