Reputation: 18787
I want to find positions of all elements of array with specific value. Example:
def numbers = [1, 2, 3, 4, 5, 6, 5, 4, 6, 4, 9, 2];
I want to find positions of 4
, here position numbers are 3,7,9
How to find it elegant with nice groovy collections methods?
Upvotes: 8
Views: 7622
Reputation: 18787
I have found the solution:
println numbers.findIndexValues {
it == 4;
}
Groovy is amazing!!!
Upvotes: 14