Is there a good reason why there is no Pair
in Java? What would be the equivalent of this C++ construct? I would rather avoid reimplementing my own.<
The shortest pair that I could come up with is the following, using Lombok:
@Data
@AllArgsConstructor(staticName = "of")
public class Pair {
private F first;
private S second;
}
It has all the benefits of the answer from @arturh (except the comparability), it has hashCode
, equals
, toString
and a static “constructor”.