Skip to content

Instantly share code, notes, and snippets.

@AL3X-69
Created November 17, 2025 16:18
Show Gist options
  • Select an option

  • Save AL3X-69/4747301d5b9a9821f585856cce40756b to your computer and use it in GitHub Desktop.

Select an option

Save AL3X-69/4747301d5b9a9821f585856cce40756b to your computer and use it in GitHub Desktop.
Simple Java Pair object implementation
package dev.alex6.tsle.utils;
import java.util.Objects;
public class Pair<A, B> {
private A a;
private B b;
public Pair() {}
public Pair(A a, B b) {
this.a = a;
this.b = b;
}
public A getA() {
return a;
}
public void setA(A a) {
this.a = a;
}
public B getB() {
return b;
}
public void setB(B b) {
this.b = b;
}
@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equals(a, pair.a) && Objects.equals(b, pair.b);
}
@Override
public int hashCode() {
return Objects.hash(a, b);
}
@Override
public String toString() {
return String.format("(%s, %s)", a, b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment