Hi, I have two ArrayList containing objects(POJO) of same type.I need to compare these tow ArrayLists on the basis of one attribute of the object. Currently I am interating both lists and comparing a specific attribute. I read about comparable interface and it did not seem to make much sense to me as there also I will have to iterate both lists and then call compareTo method. Pls advice .
Comparable provides a standard interface for comparing objects. It's very helpful in implementing standard sort routines, ordered containers, and such. In your particular situation, it wouldn't help anything.
Perhaps you could implement equals() in this POJO class so that it just compares this one attribute; then ArrayList's equals() method would do exactly what you want.