Returns a reversed view of the specified list. For example, Lists.reverse(Arrays.asList(1, 2, 3)) returns a list containing 3, 2, 1. The returned list is backed by this list, so changes in the returned list are reflected in this list, and vice-versa. The returned list supports all of
(List<T> list)
| 821 | * @since 7.0 |
| 822 | */ |
| 823 | public static <T> List<T> reverse(List<T> list) { |
| 824 | if (list instanceof ImmutableList) { |
| 825 | return ((ImmutableList<T>) list).reverse(); |
| 826 | } else if (list instanceof ReverseList) { |
| 827 | return ((ReverseList<T>) list).getForwardList(); |
| 828 | } else if (list instanceof RandomAccess) { |
| 829 | return new RandomAccessReverseList<T>(list); |
| 830 | } else { |
| 831 | return new ReverseList<T>(list); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | private static class ReverseList<T> extends AbstractList<T> { |
| 836 | private final List<T> forwardList; |
no test coverage detected