I want to return two objects from a Java method and was wondering what could be a good way of doing so?
The possible ways I can think of are: return a HashMap<
Apache Commons has tuple and triple for this:
ImmutablePair
An immutable pair consisting of two Object
elements.ImmutableTriple
An immutable triple consisting of
three Object elements.MutablePair
A mutable pair consisting of
two Object elements.MutableTriple
A mutable triple
consisting of three Object elements.Pair
A pair consisting of
two elements.Triple
A triple consisting of three elements.Source: https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/tuple/package-summary.html