1 Replies - 238 Views - Last Post: 15 March 2012 - 09:22 AM Rate Topic: -----

#1 tishan_pubudu  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 14-June 10

There are still duplicates in my set(java.util.set)

Posted 15 March 2012 - 08:00 AM

I used a LinkedHashSet to get rid of some duplicate objects in a list. First I created a new LinkedHashSet
Set<Node> nodes = new LinkedHashSet<Node>();
where Node is just a data structure like this.
public class Node {
	private int id;
	private String place;
	private String latitude;
	private String longtitude;
}


I also override the equals function of Node
public boolean equals(Object o) {
	Node n = (Node) o;
	if (this.id==n.id) {
		return true;
	} else {
		return false;
	}
	



But still I get duplicate nodes inside my Set. Any idea what went wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: There are still duplicates in my set(java.util.set)

#2 tishan_pubudu  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 6
  • Joined: 14-June 10

Re: There are still duplicates in my set(java.util.set)

Posted 15 March 2012 - 09:22 AM

Got it. There was a problem with overriding HashCode() :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1