org.apache.commons.math3.util

## Class Pair<K,V>

- java.lang.Object
- - org.apache.commons.math3.util.Pair<K,V>

- Type Parameters:
    `K` - Key type.
    `V` - Value type.
  Direct Known Subclasses:
    PointValuePair, PointValuePair, PointVectorValuePair, PointVectorValuePair

      public class Pair<K,V>
      extends 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.
  Since:
    3.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Pair(K k, V v)` Create an entry representing a mapping from the specified key to the specified value.
    `Pair(Pair<? extends K,? extends V> entry)` Create an entry representing the same mapping as the specified entry.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <K,V> Pair<K,V>` | `create(K k, V v)` Convenience factory method that calls the `constructor`.
    `boolean` | `equals(Object o)` Compare the specified object with this entry for equality.
    `K` | `getFirst()` Get the first element of the pair.
    `K` | `getKey()` Get the key.
    `V` | `getSecond()` Get the second element of the pair.
    `V` | `getValue()` Get the value.
    `int` | `hashCode()` Compute a hash code.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Pair

          public Pair(K k,
              V v)

      Create an entry representing a mapping from the specified key to the specified value.
      Parameters:
        `k` - Key (first element of the pair).
        `v` - Value (second element of the pair).

    - #### Pair

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

      Create an entry representing the same mapping as the specified entry.
      Parameters:
        `entry` - Entry to copy.

  - ### Method Detail

    - #### getKey

          public K getKey()

      Get the key.
      Returns:
        the key (first element of the pair).

    - #### getValue

          public V getValue()

      Get the value.
      Returns:
        the value (second element of the pair).

    - #### getFirst

          public K getFirst()

      Get the first element of the pair.
      Returns:
        the first element of the pair.
      Since:
        3.1

    - #### getSecond

          public V getSecond()

      Get the second element of the pair.
      Returns:
        the second element of the pair.
      Since:
        3.1

    - #### equals

          public boolean equals(Object o)

      Compare the specified object with this entry for equality.
      Overrides:
        `equals` in class `Object`
      Parameters:
        `o` - Object.
      Returns:
        `true` if 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:
        `hashCode` in class `Object`
      Returns:
        the hash code value.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### create

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

      Convenience factory method that calls the `constructor`.
      Type Parameters:
        `K` - the key type
        `V` - the value type
      Parameters:
        `k` - First element of the pair.
        `v` - Second element of the pair.
      Returns:
        a new `Pair` containing `k` and `v`.
      Since:
        3.3

Copyright © 2003–2016 The Apache Software Foundation. All rights reserved.