This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How do you remove duplicate Point Objects in an array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do you remove duplicate Point Objects in an array?" Watch "How do you remove duplicate Point Objects in an array?" New topic
Author

How do you remove duplicate Point Objects in an array?

H Lee
Greenhorn

Joined: Mar 31, 2008
Posts: 2
I have an Point2D class that stores information about the x and y coordinates of a point object and it also contains getters.

When I create an array of point objects I dont know how i can remove duplicates if there are any?

Any other ways I can remove cuplicate Point objects from an array?

Thanks
[ March 31, 2008: Message edited by: H Lee ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"go999",
Please check your private messages regarding an important administrative matter.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ravikanth kolli
Ranch Hand

Joined: Feb 10, 2008
Posts: 179

hi
Are you checking for similar x and y coordinates or the same point?

If you are checking for similar points, a much easier approach is to use "sets" in java to eliminate duplication of elements.

hope this helps..


-kolli
H Lee
Greenhorn

Joined: Mar 31, 2008
Posts: 2
Im checking if there are two points that are equal to each other.
By equal I mean that their X coordinates must be equal and their Y coordinates must be equal.
colton peterson
Ranch Hand

Joined: Nov 18, 2007
Posts: 97

There are Collections that can remove duplicates (check api in java.util I am not sure if ArrayList removes duplicates but there is something that will, I am pretty sure that is what they meant by sets) they will tell if it is a duplicate usually by the equals() method found in object. If that is not what you want then you can subclass Points2D and override the equals() method to check for the X and Y.

Also in java.awt.Point (a subclass of Point2D) there is already an overrided equals() method.
[ March 31, 2008: Message edited by: colton peterson ]

www.mormon.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you remove duplicate Point Objects in an array?
 
Similar Threads
vector?
arrays & final
help
remove duplicates from an array
garbage collection