I need a Map to make a cache in Java for same values that I have two String keys. My question it\'s better to make nested Maps (one for each key) or make some type of custom
I think that using nested maps is less optimal way.
I agree with your second thought - implement a custom class with overriden hashCode
public int hashCode(){
return str1+str2.hashCode();
}
and equals
public boolean equals(Object o){
//compare both keys here
}
Also don't forget to override the same methods in the stored object's class.
Then, in case of ["ab", "c"] you will have the same hash code, but different equals result