I am trying to associate two values of different datatypes [one long and the other a string] to a single key in a Java HashMap. I have looked around and suggestions to similar problems include, using the MultiValuedMap from the Apache Collections Framework or using the MultiMap from Guava. However I think these may be overkill plus I would not like to add extra binaries to my system.
Is there anything wrong with defining a class such as:
class X {
long value1;
String value2;
X(long v, String w) { this.value1 = v; this.value2 = w;}
}
While inserting into the HashMap do this:
X obj = new X(1000, "abc");
map.add("key", obj)
Are there any glaring drawbacks with this approach? I am looking for a solution that scales well in lookup.
Thanks!