Is there available a proven Java Pair class implementation?
I mean readily available, widely accepted and tested, maybe part of a more extensive library such as Apache Commons or Guava.
The implementation of Pair class contains the following components: Two public fields: first and second, just like in C++. A private constructor: takes two arguments – a key and, its corresponding value. Method of(): A static factory method for creating an immutable, Typed Pair instance.
To sum it up: a generic Pair class doesn't have any special semantics and you could as well need a Tripplet class etc. The developers of Java thus didn't include a generic Pair but suggest to write special classes (which isn't that hard) like Point(x,y) , Range(start, end) or Map.
Pair class which can be used to store a pair. We need to store the values into Pair using the parameterized constructor provided by the javafx. util. Pair class.
A mutable pair consists of two object elements. MutablePair is defined in the Apache Commons Lang. The package has to be added to the classpath before MutablePair is used.
Yes, have a look at Apache Commons Pair
.
Use sparingly, if at all; left
and right
doesn't really convey anything about the content or relation between the elements.
(The Pair
class was deliberately left out of the standard Java API.)
Map.Entry
What about java.util.Map.Entry
interface?
Two concrete implementation bundled with Java 6 and later:
java.util.AbstractMap.SimpleEntry
java.util.AbstractMap.SimpleImmutableEntry
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With