I have a Java Set<MyClass>
on which I've overridden equals
and hashCode
to use the String name;
variable.
public class MyClass{
final String name;
public boolean equals(Object o){...}
public int hashCode(){return name.hashCode();}
}
Is there anyway I can get my Object out of the HashSet using something like
MyClass o = set.get("nameofmyobject");
Is there a way to do this in Java, or a datastructure? or do I need to change up all of my Sets to Maps?