Hi All,
I am in the process of writing a small program where I have created a very simple class called Vertex that has a
String as a field. I am now attempting to add a number of instances of my Vertex class into a HashSet. However, my resultant HashSet has duplicates in it.
I have added a equals method and compareTo method in my Vertex class to attempt to allow my HashSet to uniquely identify Vertexes but I am clearly missing something. Can anyone point me in the right direction. Do I need to override the HashCode in my Vertex class?
This results in a Set of [A, B, A, C] when I would like to have no duplicates, hence my choice in using a Set.
Thanks in advance