The fromCollection() method in org.javatuples is used to instantiate a tuple in a semantically elegant way, with the values of the collection, given as parameters. This method can be used to any tuple class object of 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 collection.
public static <X> TupleClass<X> fromCollection(Collection<X> collection)
TupleClass<X> obj = TupleClass.fromCollection(Collection<X> collection)
Parameters: This method takes collection as parameter where:
- X– represents the datatype of values in the collection.
- collection– represents the collection 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 collection, passed as the parameters.
Below programs illustrate the various ways to use fromCollection() method:
Program 1: Using fromCollection() with Unit class:
Program 2: Using fromCollection() with Decade class:
[Geeks, for, Geeks, A, Computer, Science, Portal, for, Geeks, RishabhPrabhu]
Note: Similarly, it can be used with any other JavaTuple Class.
- JavaTuples contains() method
- JavaTuples add() method
- JavaTuples with() method
- JavaTuples fromIterable() method
- JavaTuples getKey() method
- JavaTuples hashcode() method
- JavaTuples removeFromX() method
- JavaTuples setValue() method
- JavaTuples fromArray() method
- JavaTuples setLabel() method
- JavaTuples setKey() method
- JavaTuples setAtX() method
- JavaTuples equal() method
- JavaTuples addAtX() method
- JavaTuples compareTo() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.