I would like to get last X entries of a map.
If i would like to get first entries it can be done fairly easy in groovy: map.take(10)
gets me first 10 entries of a map. But how to get LAST 10 entries? there is no map.reverse()
method.
You could use drop
like so:
map.drop( map.size() - 10 )
To drop all but the last 10 elements
An alternative would be to use the iterator
, which can be reversed:
map.iterator().reverse().take( 10 ).reverse().collect()
But it's much messier, and uses more resources
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With