JavaTuples removeFromX() method
The removeFromX() method in org.javatuples is used to remove a value from the existing tuple, from the index X. Since JavaTuples are immutable, hence removing a value from the existing tuple results in a new tuple with one value less. For example, removing a value from Pair tuple results in the formation of a Unit tuple. This method can be used for any tuple class object of the javatuples library, except the Unit class,, as Unit is the smallest class available in JavaTuples library with only 1 value. It returns the tuple class object of a class smaller than the called class.
Syntax:
Quartet<String, Integer, Double, String> quartet = ...
...
Triplet<String, Integer, Double> triplet = quartet.removeFromX();
Here X represents the index from which the value is to be removed.
Return Value: This method returns the tuple class object of a class smaller than the called class. The removed value is from the index X mentioned in the method name.
Note: This method do not exists with Unit Class, KeyValue Class, and LabelValue Class.
Below programs illustrate the various ways to use removeFromX() methods:
Program 1: When the removeFromX() method is used with any class from Pair to Decade, with a direct values as parameter:
import java.util.*;
import org.javatuples.Unit;
import org.javatuples.Pair;
class GfG {
public static void main(String[] args)
{
Pair<String, String> pair = Pair.with( "GeeksforGeeks" ,
"A computer science portal" );
Unit<String> unit = pair.removeFrom1();
System.out.println(unit);
}
}
|
Output:
[GeeksforGeeks]
Program 2:
import java.util.*;
import org.javatuples.Ennead;
import org.javatuples.Decade;
class GfG {
public static void main(String[] args)
{
Decade<Integer, Integer, Integer,
Integer, Integer, Integer,
Integer, Integer, Integer,
Integer>
decade
= Decade.with(Integer.valueOf( 1 ),
Integer.valueOf( 2 ),
Integer.valueOf( 3 ),
Integer.valueOf( 4 ),
Integer.valueOf( 5 ),
Integer.valueOf( 6 ),
Integer.valueOf( 7 ),
Integer.valueOf( 8 ),
Integer.valueOf( 9 ),
Integer.valueOf( 10 ));
Ennead<Integer, Integer, Integer,
Integer, Integer, Integer,
Integer, Integer, Integer>
ennead
= decade.removeFrom0();
System.out.println(ennead);
}
}
|
Output:
[2, 3, 4, 5, 6, 7, 8, 9, 10]
Note: Similarly, it can be used with other JavaTuple Class.
Last Updated :
27 Aug, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...