This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a scenario where i get a resultset retreived from the database. I want to remove duplicate rows provided if all the columns in the row contain duplicates. Each and every row is represented by a java bean (ie) all the columns will be set to a variable using its setter methods .I know the best solution is to go for a comparator but i havent used it . Could anyone of you guys can guide me to use it and also is there any other way to compare objects.
Anupam is right. Create an equals method that compares every data member to define equality. Comparators are used when you need alternate definitions for equality. For example, you could have different Comparators to match objects base on an id number, a name, a description, or any combination of fields.
First implement the equals method and only use Comparators when you need to override it.