Created
April 2, 2021 08:24
-
-
Save viartemev/f525d173f6fba506859f51375ca854b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ReversedView<E> extends AbstractList<E>{ | |
public static <E> List<E> of(List<E> list) { | |
return new ReversedView<>(list); | |
} | |
private final List<E> backingList; | |
private ReversedView(List<E> backingList){ | |
this.backingList = backingList; | |
} | |
@Override | |
public E get(int i) { | |
return backingList.get(backingList.size()-i-1); | |
} | |
@Override | |
public int size() { | |
return backingList.size(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment