Is there a reason there's
Lists.transform()
but no
Lists.filter()
?
How do I filter a list correctly? I could use
new ArrayList(Collection2.filter())
of course, but this way it's not guaranteed that my ordering stays the same, if I understand correctly.
It wasn't implemented because it would expose a perilous large number of slow methods, such as #get(index) on the returned List view (inviting performance bugs). And ListIterator would be a pain to implement as well (though I submitted a patch years ago to cover that).
Since indexed methods can't be efficient in the filtered List view, it's better to just go with a filtered Iterable, which doesn't have them.
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