Is there a way to use the groovy .collect method, but only up to a certain index in the source array?
For example if your source iterator was 1 million long and your limit was 100, you would end up with an array of 100 items.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you are using any data structure that implements
java.util.Listyou can do acollection.subList(0, 100)on it. Where 0 is the start index and 100 is the end. After that you’d pass the new collection intocollect().Here is an example using an object that extends
java.util.Iterator: