I've got two arraylists, and I'm looking for an efficient way to count the number of different values.
Some example lists:
List<String> list = new ArrayList<String>();
list.add("String A");
list.add("String B");
list.add("String C");
List<String> anotherlist = new ArrayList<String>();
list.add("String B");
list.add("String A");
list.add("String D");
You could do something to check for each item (because the order should not matter) if it is the same or not (pure conceptual):
for(int i=0;i<list.size();i++)
{
for(int j=0;j<anotherlist.size();j++)
{
if (item.get(i) == item.get(j)){
intDifferent = intDifferent+1;
} else {
intSame = intSame+1;
}
intTotal = intTotal+1
}
}
//Some calculations with intdifferent en inttotal to find out how many different
//values we actually have between the lists, in the case of the example, it
//should output 1
Is there a more efficient way to do this? Or is there a sample or post available on how to accomplish this?