I must be going crazy but why is Groovy findIndexValues returning List<long>? Can I get the indices in Integer?
foo = ['a','b','d','e', 'e','e']
indices = foo.findIndexValues { it == 'e'}
indices.each { println foo[it] }
The above will crash because foo collection cannot handle a long as a accessing index. Am I not using the language as it should be?
That’s how that method works. It traverses the collection with an iterator and keeps track of the matching indexes as longs. In theory, it supports collections larger than
Integer.MAX_VALUE, although I’m doubtful this is useful in practice.You can work around it with: