First of all I hope this question has not been asked before. I've looked a bit and could not find an appropriate answer :s
I'm looking for an efficient way of moving some objects from one collection to an other, when a specific condition is true.
Currently, I would do it in a pretty straightforward way, but I'm afraid this might not be optimal:
Collection<Object> myFirstCollection; //let's consider it instanciated and populated
Collection<Object> mySecondCollection; //same for this one
myFirstCollection.stream().forEach(o -> {
if ( conditionReturningTrue(o) ) {
mySecondCollection.add(o);
myFirstCollection.remove(o);
}
});
Do you know any better way / more efficient of doing that ?