VOOZH about

URL: https://www.geeksforgeeks.org/java/java-tuples-setatx-method/

⇱ JavaTuples setAtX() method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaTuples setAtX() method

Last Updated : 11 Jul, 2025
The setAtX() method in org.javatuples is used to change the value in the existing tuple, at the index X. Since JavaTuples are immutable, hence changing a value in the existing tuple results in a new tuple with the modified value at the index X. It returns the tuple class object of the called class with the changed value at index X. Syntax:
Quartet<String, Integer, Double, String> quartet = ...
 ...
Quartet otherQuartet = quartet.setAtX(value);
Here X represents the index at which the value is to be changed. Return Value: This method returns the tuple class object of the called class with the changed value at index X. Note: This method do not exists with KeyValue Class, and LabelValue Class. Below programs illustrate the various ways to use setAtX() methods: Program 1: When the setAtX() method is used with any class from Unit to Decade, with a direct values as parameter: Output:
[GeeksforGeeks, by Sandeep Jain]
Program 2:
Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 100]
Note: Similarly, it can be used with other JavaTuple Class.
Comment
Article Tags: