Finding Difference of 2 sets in Java
<p>I have two hashsets in Java, of which I want to find the difference</p>

<p>I tried the following code as recommended by Oracle's doc</p>

<pre><code>    HashSet&lt;RunningTaskInfo&gt; difference = new HashSet&lt;ActivityManager.RunningTaskInfo&gt;(newRunningTasks);
    HashSet&lt;RunningTaskInfo&gt; oldRunningTaskInfos = new HashSet&lt;ActivityManager.RunningTaskInfo&gt;(oldRunningTasks);
    difference.removeAll(oldRunningTaskInfos);

    for(RunningTaskInfo d : difference){
        ComponentName cn = d.baseActivity;
        Log.d("com.manugupt1.fua","Comparing : " + i + cn.getPackageName() + "****" + cn.getClassName() + "****" + cn.getShortClassName());

    }
</code></pre>

<p>Only those data values that are not in oldRunningTasks should be shown but I get only the elements from oldRunningTasks. Any suggestions</p>
