JavaTuple toArray() method
Last Updated :
27 Aug, 2018
The toArray() method in org.javatuples is used to convert the values in TupleClass into an array of Object type. This method is inherited from the JavaTuple class. This method can be used to any tuple class object of javatuples library. It returns an array of Object type formed with the values in the TupleClassObject.
Method Declaration:
public final Object[] toArray()
Syntax:
Object obj[] = TupleClassObject.toArray()
Here TupleClassObject represents the JavaTuple Class object used like Unit, Quintet, Decade, etc.
Return Value: This method returns an array of Object type formed with the values in the TupleClassObject.
Below are programs that will illustrate the various ways to use toArray() method:
Program 1: Using toArray() with Unit class:
import java.util.*;
import org.javatuples.Unit;
class GfG {
public static void main(String[] args)
{
Unit<String> unit = Unit.with( "GeeksforGeeks" );
Object[] object = unit.toArray();
for (Object obj : object) {
System.out.println(obj);
}
}
}
|
Output:
GeeksforGeeks
Program 2: Using toArray() 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 ));
Object[] object = unit.toArray();
for (Object obj : object) {
System.out.println(obj);
}
}
}
|
Output:
1
GeeksforGeeks
A computer portal
20.18
Note: Similarly, it can be used with any other JavaTuple Class.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...