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
it's better to make nested Maps (one for each key) or make some type of custom key maked with the two Strings?
A single hashtable with a composite key type may have better locality of reference. It will almost certainly take less memory and be a bit faster, though how much depends on your application.
Designing a custom hash function can be tricky, but you can start with a function that just takes the already-defined hashes of the composite key's members and XORs them together. You could also take the string route, but then make sure you concatenate the members with some marker in between them (such as ":") that is unlikely to occur in them.