I have a String arraylist ListA containing values, say {a,b,c,d}. I did some operations and the ListA now contains, say, {b,c,e}
I have to find out what all elements have been removed from ListA i.e a and d and what all elements have been added i.e e.
Please help. I am new to Java and am stuck with this.
you actually have 3 options what i could suggest.
have a referenceList from which you can compare the ListA after modification, so that you can list out added/removed elements.
see Noob UnChained's answer for sample code.
instead of using Arraylist, extend it and override remove() & Noob UnChained methods to add(make sure you persist a call to super() just in case) logic to store elements being removed/added.
see Evgeniy Dorofeev's answer for sample code.
instead of directly calling add()/remove() Write utility methods which will in turn call add()/remove() along with storing that element to add()/remove() from corresponding addedList & removedList
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