Is there a sane way to get an ordered stream from a list (array list specifically, but it shouldn't matter) that streams elements in reverse of how they are in the original list?
I'm looking for a solution that doesn't involve buffering data in anything (collector, another list, array, etc, because they copy the container which is wasteful), or uses
List is a random access list, you may simply use
int num=list.size()-1; IntStream.rangeClosed(0, num).mapToObj(i->list.get(num-i))
to create a
Stream which has the characteristics
ORDERED | SIZED | SUBSIZED and offers full splitting support.
For a non-random access list like
LinkedList it would be a performance disaster, however, who uses
You may also check via