Hi guys,
I have a big doubt and I hope someone can help me out. I need to delete some objects from an arraylist if they meet a condition and I'm wondering which way could be more efficient. Here's the situation: I have a class that contains an arraylist containing some other objects. I have to iterate over this arraylist and delete all elements meeting a certain condition. As far as I know, those would be my options to delete:
1 - Create a new arraylist and add the elements that doesn't meet the condition. After the iteration, swap from the old arraylist to the new one without the elements.
2 - Create a new arraylist and add the elements that meet the condition. After the iteration, use the removeAll() method passing the arraylist with the objects to be deleted.
Is there a more efficient way to delete objects from an arraylist?
Thanks in advance,
Carlos