I am using Java 6. For simplicity, everything will be publicly available.
Suppose I have this simple class.
public class A{
public String name;
public String data;
}
I want to put class A objects in a HashMap. I will use the field nameas a key, and the whole object as a value.
I will only search for an object on this map name.
My question is: for class A do I need to implement hashCodeand equalsto search for goals? Will this speed up the search? I know this will help for Sets, but I'm not sure about HashMaps whose key is just String.
source
share