CollectionUtils { @Nullable public static <T> T last( Collection<T> input ) { if ( input.size() == 0 ) return null; ArrayList<T> tmp = Lists.newArrayList(); tmp.addAll( input ); return tmp.get( tmp.size() - 1 ); }  static int count( List<T> list, T value ); static void filter( Collection<V> input, Predicate<V> predicate ); static void startsWith( Collection<V> input, final String prefix ); static ImmutableList<V> startingWith( Collection<V> input, final String prefix  ); static List<T> shuffle( List<T> list ); static List<List<T>> group( Collection<T> input, int groupSize ); static List<List<T>> group( Collection<T> input, int groupSize, boolean partial ); static T first( Collection<T> input ); @Nullable static T last( Collection<T> input ); static List<T> head( Collection<T> input, int count ); static List<T> tail( Collection<T> input, int count ); static List<T> sort( Collection<T> input ); static List<T> sort( Collection<T> input, Comparator<T> comparator ); static List<String> strings( Collection<T> input ); static ImmutableList<String> toStrings( Collection<T> input ); static List<T> trim(List<T> list, int count);  }
@Test public void testlast() throws Exception { List<Integer> list; list = Lists.newArrayList(); assertEquals( null, last( list ) ); list = Lists.newArrayList( 1 ); assertEquals( new Integer( 1 ), last( list ) ); list = Lists.newArrayList( 1, 2 ); assertEquals( new Integer( 2 ), last( list ) ); }