JavaTuple toList() method
The toList() method in org.javatuples is used to convert the values in TupleClass into a List. This List is of Object type, so that it can take all values. It is inherited from the JavaTuple class. This method can be used to any tuple class object of javatuples library. It returns List formed with the values in the TupleClassObject.
Method Declaration:
public final List<Object> toList()
Syntax:
List<Object> list = TupleClassObject.toList()
Here TupleClassObject represents the JavaTuple Class object used like Unit, Quintet, Decade, etc.
Return Value: This method returns a List formed with the values in the TupleClassObject.
Below are programs that will illustrate the various ways to use toList() method:
Program 1: Using toList() with Unit class:
// Below is a Java program to use toList() method import java.util.*; import org.javatuples.Unit; class GfG { public static void main(String[] args) { // Creating an Unit with one value Unit<String> unit = Unit.with("GeeksforGeeks"); // Using toList() method with Object type List<Object> objList = unit.toList(); // Printing the list System.out.println(objList); } } |
Output:
[GeeksforGeeks]
Program 2: Using toList() with Quartet class:
// Below is a Java program to use toList() method import java.util.*; import org.javatuples.Quartet; class GfG { public static void main(String[] args) { // Creating a quartet Quartet<Integer, String, String, Double> quartet = Quartet.with(Integer.valueOf(1), "GeeksforGeeks", "A computer portal", Double.valueOf(20.18)); // Using toList() method with Object type List<Object> objList = quartet.toList(); // Printing the list System.out.println(objList); } } |
Output:
[, GeeksforGeeks, A computer portal, 20.18]
Note: Similarly, it can be used with any other JavaTuple Class.
Recommended Posts:
- JavaTuple getValueX() method
- JavaTuple toArray() method
- JavaTuple lastIndexOf() method
- Collectors toList() method in Java with Examples
- Method Class | getGenericExceptionTypes() Method in Java
- Method Class | isBridge() Method in Java
- Method Class | getName() Method in Java
- Method Class | equals() Method in Java
- Method Class | hashCode() Method in Java
- Method Class | getExceptionTypes() Method in Java
- Method Class | getDeclaringClass() method in Java
- Method Class | getParameterCount() method in Java
- Method Class | getModifiers() method in Java
- Method Class | getDeclaredAnnotations() method in Java
- Method Class | getAnnotation() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



