Java examples for java.util:Collection Operation
get Last Item from a Collection
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static void main(String[] argv) { Collection items = java.util.Arrays.asList("asdf", "java2s.com"); System.out.println(getLastItem(items)); }//from ww w.ja va 2s .com public static Object getLastItem(Collection items) { Object nextObject = new Object(); Iterator i = items.iterator(); while (i.hasNext()) { nextObject = i.next(); } return nextObject; } }