Top Description Fields Constructors Methods
org.apache.commons.math3.util

public Class Pair<K, V>

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.commons.math3.optim.PointValuePair, org.apache.commons.math3.optim.PointVectorValuePair, org.apache.commons.math3.optimization.PointValuePair, org.apache.commons.math3.optimization.PointVectorValuePair
Type Parameters
<K>
Key type.
<V>
Value type.

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.
Since
3.0

Field Summary

Modifier and TypeField and Description
private final K
key

Key.

private final V
value

Value.

Constructor Summary

AccessConstructor and Description
public
Pair(K
Key (first element of the pair).
k
,
V
Value (second element of the pair).
v
)

Create an entry representing a mapping from the specified key to the specified value.

public
Pair(Pair<? extends K, ? extends V>
Entry to copy.
entry
)

Create an entry representing the same mapping as the specified entry.

Method Summary

Modifier and TypeMethod and Description
public static <
the key type
K
,
the value type
V
>
Pair<K, V>

Returns:

a new Pair containing k and v.
create
(K
First element of the pair.
k
,
V
Second element of the pair.
v
)

Convenience factory method that calls the constructor.

public boolean

Returns:

true if the given object is also a map entry and the two entries represent the same mapping.
equals
(Object
Object.
o
)

Overrides java.lang.Object.equals.

Compare the specified object with this entry for equality.

public K

Returns:

the first element of the pair.
getFirst
()

Get the first element of the pair.

public K

Returns:

the key (first element of the pair).
getKey
()

Get the key.

public V

Returns:

the second element of the pair.
getSecond
()

Get the second element of the pair.

public V

Returns:

the value (second element of the pair).
getValue
()

Get the value.

public int

Returns:

the hash code value.
hashCode
()

Overrides java.lang.Object.hashCode.

Compute a hash code.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

keyback to summary
private final K key

Key.

valueback to summary
private final V value

Value.

Constructor Detail

Pairback to summary
public Pair(K k, V v)

Create an entry representing a mapping from the specified key to the specified value.

Parameters
k:K

Key (first element of the pair).

v:V

Value (second element of the pair).

Pairback to summary
public Pair(Pair<? extends K, ? extends V> entry)

Create an entry representing the same mapping as the specified entry.

Parameters
entry:Pair<? extends K, ? extends V>

Entry to copy.

Method Detail

createback to summary
public static <K, V> Pair<K, V> create(K k, V v)

Convenience factory method that calls the constructor.

Parameters
<K>
the key type
<V>
the value type
k:K

First element of the pair.

v:V

Second element of the pair.

Returns:Pair<K, V>

a new Pair containing k and v.

Since
3.3
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Compare the specified object with this entry for equality.

Parameters
o:Object

Object.

Returns:boolean

true if the given object is also a map entry and the two entries represent the same mapping.

Annotations
@Override
getFirstback to summary
public K getFirst()

Get the first element of the pair.

Returns:K

the first element of the pair.

Since
3.1
getKeyback to summary
public K getKey()

Get the key.

Returns:K

the key (first element of the pair).

getSecondback to summary
public V getSecond()

Get the second element of the pair.

Returns:V

the second element of the pair.

Since
3.1
getValueback to summary
public V getValue()

Get the value.

Returns:V

the value (second element of the pair).

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Compute a hash code.

Returns:int

the hash code value.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override