Diffing two lists of business objects dataListOne and dataListTwo will be full of BO objects (around 4000 - 5000).

Lets say dataListOne comes with objects with business keys: "one,two,three,one"
and dataListTwo has: "three,four,five".

At the end I must have:


insertList: "one,two"
updateList: "three"
deactivateList: "four,five"


There may be 2 BO's with same business key but different properties but I do not care about that.. So once I process a BO which has a businessKey "one" in dataListOne, if there comes another, I will not care about it..

What kind of approach should I take?

/*
Base Business Objects are considered to be same if they have the same businessKey !
 */
public class DataDiffContainer&lt;BO extends BaseBusinessObject&gt; {

    private List&lt;BO&gt; insertList = new ArrayList&lt;BO&gt;();
    private List&lt;BO&gt; updateList = new ArrayList&lt;BO&gt;();
    private List&lt;BO&gt; deactivateList = new ArrayList&lt;BO&gt;();

    private Set&lt;String&gt; handledString = new HashSet&lt;String&gt;();


    public void performDiff(List&lt;BO&gt; dataListOne, List&lt;BO&gt; dataListTwo) {
        for (BO dataOne : dataListOne) {
            if (handledString.contains(dataOne.getBusinessKey())) {
                // See the comment above class declaration
                continue;
            }
            boolean found = false;
            for (BO dataTwo : dataListTwo) {
                if (dataTwo.equals(dataOne)) {
                    updateList.add(dataOne);
                    dataListTwo.remove(dataTwo);
                    // we already know what to do with this object,
                    // so we may as well remove from the List that we need to check..
                    found = true;
                    break;
                }
            }
            if (!found) {
                insertList.add(dataOne);
            }
            handledString.add(dataOne.getBusinessKey());
        }

        // What is remaining in dataListTwo data should be dectivated:
        for (BO bo : dataListTwo) {
            if (bo.isActive())
                deactivateList.add(bo);
        }
    }
}
I would go down the simple road:

1) Converting both lists to sets

2) Use set operations:

    Set&lt;Integer&gt; update = new HashSet&lt;&gt;(list1);
    Set&lt;Integer&gt; insert = new HashSet&lt;&gt;(list1);
    Set&lt;Integer&gt; delete = new HashSet&lt;&gt;(list2);
    update.retainAll(delete);
    insert.removeAll(delete);
    delete.removeAll(update);


Done.

Even if it is not the fastest solution, it should not be too bad for only 5k objects. It is simple, readable and not errorprone.