Create Decade Tuple from a List collection in Java

Java 8Object Oriented ProgrammingProgramming

<p>Use the fromCollection() method to create a Decade tuple from a List collection in Java. Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following package.</p><pre class="result notranslate">import org.javatuples.Decade;</pre><p><strong>Note</strong> Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -&gt; Properties -&gt; Java Build Path -&gt; Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples.</p><p><strong>Steps:</strong> <a href="https://www.tutorialspoint.com/how-to-run-javatuples-program-in-eclipse" target="_blank">How to run JavaTuples program in Eclipse</a></p><p>The following is an example to create Decade Tuple from a List collection in Java.</p><h2>Example</h2><pre class="prettyprint notranslate">import java.util.List; import org.javatuples.Decade; import java.util.*; public class Demo { &nbsp; &nbsp;public static void main(String[] args) { &nbsp; &nbsp; &nbsp; // 10 elements in the List &nbsp; &nbsp; &nbsp; List&lt;String&gt; myList = new ArrayList&lt;String&gt; (); &nbsp; &nbsp; &nbsp; myList.add(&quot;Football&quot;); &nbsp; &nbsp; &nbsp; myList.add(&quot;Cricket&quot;); &nbsp; &nbsp; &nbsp; myList.add(&quot;Tennis&quot;); &nbsp; &nbsp; &nbsp; myList.add(&quot;Hockey&quot;); &nbsp; &nbsp; &nbsp; myList.add(&quot;Badminton&quot;); &nbsp; &nbsp; &nbsp; myList.add(&quot;Archery&quot;); &nbsp; &nbsp; &nbsp; myList.add(&quot;Billiards&quot;); &nbsp; &nbsp; &nbsp; myList.add(&quot;Cycling&quot;); &nbsp; &nbsp; &nbsp; myList.add(&quot;Handball&quot;); &nbsp; &nbsp; &nbsp; myList.add(&quot;Squash&quot;); &nbsp; &nbsp; &nbsp; // creating Decade Tuple from List &nbsp; &nbsp; &nbsp; Decade&lt;String, String, String, String, String, String, String, String, String, String&gt; &nbsp; &nbsp; &nbsp; d = Decade.fromCollection(myList); &nbsp; &nbsp; &nbsp; System.out.println(&quot;Elements in the Decade Tuple = &quot;); &nbsp; &nbsp; &nbsp; for (Object ele : d) System.out.println(ele); &nbsp; &nbsp;} }</pre><h2>Output</h2><pre class="result notranslate">Elements in the Decade Tuple = Football Cricket Tennis Hockey Badminton Archery Billiards Cycling Handball Squash</pre>
raja
Updated on 30-Jul-2019 22:30:25

Advertisements