The getValue() method in org.javatuples is used to fetch the value of the TupleClassObject from the index passed as the parameter. This method can be used to any tuple class object of javatuples library. It returns a Object value which is the element present at the index, passed as parameter, of the TupleClassObject. Since the returned Value is of Object type, hence using getValue() loses the type-safety.
public final Object getValue(int pos)
Object val = TupleClassObject.getValue(int pos)
Here TupleClassObject represents the JavaTuple Class object used like Unit, Quintet, Decade, etc.
Parameters: This method takes pos as parameter where:
- pos– is the index at which the value of the TupleClassObject is to be known.
- TupleClassObject– represents the JavaTuple Class object used like Unit, Quintet, Decade, etc.
Return Value: This method returns a Object value which is the element present at the index, passed as parameter, of the TupleClassObject.
Below programs illustrate the various ways to use getValue() method:
Program 1: Using getValue() with Unit class:
Value at 0 = GeeksforGeeks
Program 2: Using getValue() with Quartet class:
Value at 2 = for geeks
Note: Similarly, it can be used with any other JavaTuple Class.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.