JavaTuples toString() method
The toString() method in org.javatuples is used to convert the values in TupleClass into a String. This method is inherited from the JavaTuple class. This method can be used to any tuple class object of javatuples library. It returns a String value formed with the values in the TupleClassObject.
Method Declaration:
public final String toString()
Syntax:
String str = TupleClassObject.toString()
Here TupleClassObject represents the JavaTuple Class object used like Unit, Quintet, Decade, etc.
Return Value: This method returns a String value which contains the elements of the TupleClassObject, separated by ‘, ‘.
Below programs illustrate the various ways to use toString() method:
Program 1: Using toString() with Unit class:
import java.util.*;
import org.javatuples.Unit;
class GfG {
public static void main(String[] args)
{
Unit<String> unit = Unit.with( "GeeksforGeeks" );
String str = unit.toString();
System.out.println(str);
}
}
|
Output:
[GeeksforGeeks]
Program 2: Using toString() with Quartet class:
import java.util.*;
import org.javatuples.Quartet;
class GfG {
public static void main(String[] args)
{
Quartet<Integer, String, String, Double> quartet
= Quartet.with(Integer.valueOf( 1 ),
"GeeksforGeeks" ,
"A computer portal" ,
Double.valueOf( 20.18 ));
String str = quartet.toString();
System.out.println(str);
}
}
|
Output:
[1, GeeksforGeeks, A computer portal, 20.18]
Note: Similarly, it can be used with any other JavaTuple Class.
Last Updated :
27 Aug, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...