JavaTuples fromIterable() method
The fromIterable() method in org.javatuples is used to instance a tuple in a semantically elegant way, with the values of the iterable, given as parameters. This method can be used for any tuple class object of the javatuples library. It is a static function in each javatuple class and it returns the tuple class object of the called class, with the values initialized by the corresponding values of the iterable.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public static <X> TupleClass<X> fromIterable(Iterable<X> iterable)
TupleClass<X> obj = TupleClass.fromIterable(Iterable<X> iterable)
Parameters: This method takes iterable as parameter where:
- X– represents the datatype of values in the iterable.
- iterable– represents the iterable of values to be inserted into TupleClass.
- TupleClass– represents the JavaTuple Class used like Unit, Quintet, Decade, etc.
Return Value: This method returns the object of TupleClass, which calls the method, with the values of the iterable, passed as the parameters.
Below programs illustrate the various ways to use fromIterable() method:
Program 1: Using fromIterable() with Unit class:
Program 2: Using fromIterable() with Decade class:
[Geeks, for, Geeks, A, Computer, Science, Portal, for, Geeks, RishabhPrabhu]
Note: Similarly, it can be used with any other JavaTuple Class.