CollectionUtils { public static <T> List<T> tail( Collection<T> input, int count ) { List<T> result = Lists.newArrayList(); ArrayList<T> tmp = Lists.newArrayList(); tmp.addAll( input ); int start = Math.max( 0, input.size() - count ); for (int i = start; i < input.size(); i++) { if ( result.size() == count ) break; result.add( tmp.get( i ) ); } return result; }  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 testTail() throws Exception { List<Integer> list; list = Lists.newArrayList(); assertEquals( "[]", tail( list, 2 ).toString() ); list = Lists.newArrayList(1); assertEquals( "[1]", tail( list, 2 ).toString() ); list = Lists.newArrayList(1,2); assertEquals( "[1, 2]", tail( list, 2 ).toString() ); list = Lists.newArrayList(1,2,3); assertEquals( "[2, 3]", tail( list, 2 ).toString() ); list = Lists.newArrayList(1,2,3,4); assertEquals( "[3, 4]", tail( list, 2 ).toString() ); }