Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Lists.reverse() API. It returns a reversed view of the specified list.
package com.bethecoder.tutorials.guava.collection_tests; import java.util.List; import com.google.common.collect.Lists; public class ListReverseTest { /** * @param args */ public static void main(String[] args) { List<Integer> intList = Lists.newArrayList(1, 2, 3, 4, 5, 6); System.out.println(intList); intList = Lists.reverse(intList); System.out.println(intList); } }
[1, 2, 3, 4, 5, 6] [6, 5, 4, 3, 2, 1]