Package org.apache.commons.math4.util
Class Pair<K,V>
java.lang.Object
org.apache.commons.math4.util.Pair<K,V>
- Type Parameters:
K- Key type.V- Value type.
public class Pair<K,V>
extends java.lang.Object
Generic pair.
Although the instances of this class are immutable, it is impossible to ensure that the references passed to the constructor will not be modified by the caller.
Although the instances of this class are immutable, it is impossible to ensure that the references passed to the constructor will not be modified by the caller.
- Since:
- 3.0
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description static <K, V> Pair<K,V>create(K k, V v)Convenience factory method that calls theconstructor.booleanequals(java.lang.Object o)Compare the specified object with this entry for equality.KgetFirst()Get the first element of the pair.KgetKey()Get the key.VgetSecond()Get the second element of the pair.VgetValue()Get the value.inthashCode()Compute a hash code.java.lang.StringtoString()
-
Constructor Details
-
Method Details
-
getKey
Get the key.- Returns:
- the key (first element of the pair).
-
getValue
Get the value.- Returns:
- the value (second element of the pair).
-
getFirst
Get the first element of the pair.- Returns:
- the first element of the pair.
- Since:
- 3.1
-
getSecond
Get the second element of the pair.- Returns:
- the second element of the pair.
- Since:
- 3.1
-
equals
public boolean equals(java.lang.Object o)Compare the specified object with this entry for equality.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- Object.- Returns:
trueif the given object is also a map entry and the two entries represent the same mapping.
-
hashCode
public int hashCode()Compute a hash code.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code value.
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
create
Convenience factory method that calls theconstructor.- Type Parameters:
K- the key typeV- the value type- Parameters:
k- First element of the pair.v- Second element of the pair.- Returns:
- a new
Paircontainingkandv. - Since:
- 3.3
-