I have a list of objects and I want to create another list, which will include only objects for which the method acceptable()
returns "true". My problem is that I want to make this selection done only on demand. In other words, I want a new list to be calculated and populated only when its iterator()
method is called. Are there any libraries for that in Java?
I'm using JDK7
Google Guava has a lot of helper methods for that type of functionality. What you want is already implemented.
Iterators.filter if you want to fiter an Iterator from a collection.
Iterables.filter if you need an instance of Iterable, for example to use it in "for-each" type of loops.
There is also Collections2.filter if you need also other collection methods to be preprocessed with the filter.
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