Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static <T> T getLastElement(Collection<T> collection) { return getElement(collection, collection.size() - 1); } public static <T> T getElement(Collection<T> collection, int index) { T element = null; if (collection != null) { int count = 0; for (T entry : collection) { if (count == index) { element = entry; } count++; } } return element; } }