Java Guava | Lists.reverse() method with Examples Last Updated : 04 Feb, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Guava's Lists.reverse() method accepts a list as a parameter and returns a reversed view of the list passed as the parameter. If the specified list is random access, then the returned list is also random-access. For example: Lists.reverse(Arrays.asList(1, 2, 3)) returns a list containing 3, 2, 1. Syntax: public static <T> List<T> reverse(List<T> list) Parameter: The method accepts list as a parameter and returns a list which is backed by this list. It means that the changes made in the returned list are reflected back in the list passed as parameter to the method and vice-versa. Return Value: The method Lists.reverse() returns the reversed view of the list passed as parameter. The returned list supports all of the optional list operations supported by the list passed as parameter. Below examples illustrate the implementation of above method: Example 1: Java // Java code to show implementation of // Guava's Lists.reverse() method import com.google.common.collect.Lists; import java.util.Arrays; import java.util.List; class GFG { // Driver's code public static void main(String[] args) { // Creating a List of Integers List<Integer> myList = Arrays.asList(1, 2, 3, 4, 5); // Using Lists.reverse() method to get a // reversed view of the specified list. Any // changes in the returned list are reflected // in the original list and vice-versa List<Integer> reverse = Lists.reverse(myList); // Displaying the reversed view of specified List System.out.println(reverse); } } Output: [5, 4, 3, 2, 1] Example 2: Java // Java code to show implementation of // Guava's Lists.reverse() method import com.google.common.collect.Lists; import java.util.Arrays; import java.util.List; class GFG { // Driver's code public static void main(String[] args) { // Creating a List of Characters List<Character> myList = Arrays.asList('H', 'E', 'L', 'L', 'O'); // Using Lists.reverse() method to get a // reversed view of the specified list. Any // changes in the returned list are reflected // in the original list and vice-versa List<Character> reverse = Lists.reverse(myList); // Displaying the reversed view of specified List System.out.println(reverse); } } Output: [O, L, L, E, H] Reference: https://google.github.io/guava/releases/23.0/api/docs/com/google/common/collect/Lists.html#reverse-java.util.List- Comment More infoAdvertise with us Next Article List sublist() Method in Java with Examples S Sahil_Bansall Follow Improve Article Tags : Java java-guava Guava-Functions Guava-Lists Practice Tags : Java Similar Reads Java lang.Long.reverse() method in Java with Examples java.lang.Long.reverse() is a built-in function in Java which returns the value obtained by reversing the order of the bits in the two's complement binary representation of the specified long value. Syntax: public static long reverse(long num) Parameter : num - the number passed Returns : the value 2 min read List sublist() Method in Java with Examples This method gives a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. Syntax: List subList(int fromIndex, int toIndex) Parameters: This function has two parameter fromIndex and toIndex, which are the starting and ending ranges respectively to create 2 min read Java Guava | Shorts.asList() method with Examples The Shorts.asList() method of Guava's Shorts Class accepts a short array as a parameter and returns a list which has the fixed size. The returned list is backed by the short array which is passed as the argument. It means the changes made in the array passed as parameter will be reflected back in th 2 min read Java Guava | Shorts.toArray() method with Examples The toArray() method of Shorts Class in the Guava library is used to convert the short values, passed as the parameter to this method, into a Short Array. These short values are passed as a Collection to this method. This method returns a Short array. Syntax: public static short[] toArray(Collection 2 min read Collections.reverse() Method in Java with Examples The reverse() method of the Collections class, as the name suggests, is used to reverse the order of elements in a list. Note: It does not sort the elements, it simply reverses their current order.This class is present in java.util package so the syntax is as follows:import java.util.Collections;Col 3 min read Comparator reversed() method in Java with examples The reversed() method of Comparator Interface in Java returns a comparator that imposes the reverse ordering of this comparator. If you use sort method of the array and passes this comparator after applying the reversed method then it will sort the array in reverse order. Syntax: default Comparator 2 min read Like