Groovy reverse card keys

I would like to get the latest X card entries.

If I wanted to get the first entries, this can be done quite easily in groovy: map.take(10)gets the first 10 entries of the map. But how to get LAST 10 records? no method map.reverse().

+5
source share
1 answer

You can use dropas follows:

map.drop( map.size() - 10 )

To delete all but the last 10 items

An alternative could be a use iteratorthat can be reversed:

map.iterator().reverse().take( 10 ).reverse().collect()

But it is much more random, and uses more resources.

+4
source

All Articles