This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList Compare

 
Ananth Ram
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

public class ContactVO implements Serializable{

private String email;
private String name;
}

I created 2 arraylist based on the above VO which holds name and email address.

I would like to compare the 2 arraylist based on email address so that the new arraylist should not hold duplicate email address. Could some one give me some tip on the approach.

Thanks,
Ananth
 
Justin Fox
Ranch Hand
Posts: 802
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what you could do is something like the following.




this should be kind of what you are looking for.
this will compare each item in the firstlist with the same
corresponding index as the second.

if you want to search the whole second list for the i'th
value in the firtlist, you'll need to implement a nested
search.

and by the way, the ArrayList.get(index) returns an object, thats
why I casted.

I strongly recommend that you use the API provided on suns website, it
helps out a whole lot.

click here for the arraylist on javas site

Justin Fox
 
Ananth Ram
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the guidelines, and the 2 arraylist are of different size.

What shall I do to compare the email address and store it in a new arraylist.

Thanks,

Ananth
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you be ok to just put them into a Set? Sets reject duplicate entries based on e1.equals(e2), so if you addAll() with both lists you'll wind up witl all unique values.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic