Using a random word generator we will show how to take the first number of elements from an arraylist. take()
was introduced in Groovy 1.8.1 and can also be applied to iterable. In addition to take()
a range of indices can be used to obtain a sublist. In a comparable example we demonstrate how to limit a specified number of elements from arraylist in java.
Limit using range
Limit number of strings
Limit number of integers