VOOZH about

URL: https://www.geeksforgeeks.org/java/javatuple-getvaluex-method/

⇱ JavaTuple getValueX() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaTuple getValueX() method

Last Updated : 11 Jul, 2025
The getValueX() method in org.javatuples is used to fetch the value of the TupleClassObject from the index X. This method can be used to any tuple class object of javatuples library. It returns the value at index X of the TupleClassObject. The returned Value is of the type of X element of the TupleClassObject. Hence using getValueX() retains the type-safety, unlike getValue(X). The value of X lies from 0 to the range of the number of elements present in the TupleClassObject, minus 1. It means that for Unit class, the value of X available is 0. Similarly for Decade class, the value available for X are 0, 1, 2, .. to 9. Method Declaration:
public A getValueX()
Syntax:
A val = TupleClassObject.getValueX()
Here:
  • TupleClassObject represents the JavaTuple Class object used like Unit, Quintet, Decade, etc.
  • A represents the type of the X element
  • X represents the index of the value to be fetched
Return Value: This method returns the value at index X of the TupleClassObject. The returned Value is of the type of X element of the TupleClassObject. Below are programs that will illustrate the various ways to use getValueX() method: Program 1: Using getValueX() with Unit class: Output:
Value at 0 = GeeksforGeeks
Program 2: Using getValueX() with Quartet class:
Output:
Value at 3 = 20.18
Note: Similarly, it can be used with any other JavaTuple Class.
Comment
Article Tags: