So long story short, unlike c# that has value tuples since version 7 and you can use
(string name, int age) info = GetStudentInfo("100-000-1000");
As you can see, it is a tuple, but elements have strong types and names. You can compare them and most of it works nicely. Python is scripting language and has had this support for ages. In java, if you create a class you need to override its hashcode, tostring, ... and if you want to have multi threading guarantees it is just hard.
Thankfully Google engineers have stumbled upon this multiple times and have solved this issue as best as it is possible, for more info check out Guava horrible ideas:
https://github.com/google/guava/wiki/IdeaGraveyard
The solution is to use AutoValue that generates immutable value classes
https://github.com/google/auto/tree/master/value
import com.google.auto.value.AutoValue;
@AutoValue
public abstract class Pair {
public static Pair of(int first, int second) {
return new AutoValue_Pair(first, second);
}
public abstract int first();
public abstract int second();
}
To use it you could just type
Hashtable<Pair, String> marks = new Hashtable<Pair, String>();
marks.put(Pair.of(1, 2), "test");
The real strengths start to shine when you scale your problem or when you use it with google guava with it. For example:
Map<Pair, String> map = Maps.newLinkedHashMap();