I have two numbers and I want to use them together as a key in a Map
. Currently, I\'m concatenating their string representations. For example, suppose the key n
Why should writing all that extra code to make a full blown class that you don't need for anything else be better than using a simple String? Will computing the hash code for instances of that class be much faster than for the String? I don't think so.
Unless you are running in an extremely limited computing power environment, the overhead of making and hashing Strings should not be noticeably larger than that of instantiating your custom class.
I guess the fastest way would be to simply pack the ints into a single Long as ZZ Coder suggested, but in any case, I don't expect the speed gains to be substantial.
You need write the right eqauls and hashcode methods , or produce some bugs.