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.
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:
[5, 4, 3, 2, 1]
[O, L, L, E, H]
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.