public class Pair<A,B> extends Object
getFirst() and getSecond() methods. Equality
and hashing are defined in the natural way.
This type is devoid of semantics, best used for simple mechanical aggregations of unrelated values in implementation code. Avoid using it in your APIs, preferring an explicit type that conveys the exact semantics of the data. For example, instead of:
Pair to accomplish this; consider using the utilities com.google.common.labs.collect.ComparisonKeys or com.google.common.labs.reflect.ValueType to help you with this instead.| Modifier and Type | Field and Description |
|---|---|
A |
first
The first element of the pair; see also
getFirst(). |
B |
second
The second element of the pair; see also
getSecond(). |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object object) |
A |
getFirst()
Returns the first element of this pair; see also
first. |
B |
getSecond()
Returns the second element of this pair; see also
second. |
int |
hashCode() |
static <A,B> Pair<A,B> |
of(A first,
B second)
Creates a new pair containing the given elements in order.
|
String |
toString() |
public final A first
getFirst().public final B second
getSecond().public static <A,B> Pair<A,B> of(@Nullable A first, @Nullable B second)
public String toString()
This implementation returns a string in the form
(first, second), where first and second are the
String representations of the first and second elements of this pair, as
given by String.valueOf(Object). Subclasses are free to override
this behavior.