Create Octet Tuple from an array in Java

Java 8Object Oriented ProgrammingProgramming

<p>To create Octet Tuple from an array in Java, use the fromArray() method. Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package:</p><pre class="prettyprint notranslate">import org.javatuples.Octet;</pre><p><strong>Note:</strong> Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project &rarr; Properties &rarr; Java Build Path &rarr; Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples:</p><p>Steps: <a href="" rel="nofollow" target="_blank">How to run JavaTuples program in Eclipse</a></p><p>The following is an example to create Octet Tuple from array in Java:</p><h2>Example</h2><pre class="prettyprint notranslate">import org.javatuples.Octet; import java.util.*; public class Demo { &nbsp; &nbsp;public static void main(String[] args) { &nbsp; &nbsp; &nbsp; String[] strArr = {&quot;One&quot;, &quot;Two&quot;,&quot;Three&quot;, &quot;Four&quot;,&quot;Five&quot;, &quot;Six&quot;,&quot;Seven&quot;, &quot;Eight&quot;}; &nbsp; &nbsp; &nbsp; Octet&lt;String, String, String, String, String, String, String, String&gt; oc = Octet.fromArray(strArr); &nbsp; &nbsp; &nbsp; System.out.println(&quot;Result = &quot; + oc); &nbsp; &nbsp;} }</pre><h2>Output</h2><pre class="result notranslate">Result = [One, Two, Three, Four, Five, Six, Seven, Eight]</pre><p>Above, we have created a String array:</p><pre class="prettyprint notranslate">String[] strArr = {&quot;One&quot;, &quot;Two&quot;,&quot;Three&quot;, &quot;Four&quot;,&quot;Five&quot;, &quot;Six&quot;,&quot;Seven&quot;, &quot;Eight&quot;};</pre><p>Now, use the fromArray() method to create Octet from an array:</p><pre class="prettyprint notranslate">Octet&lt;String, String, String, String, String, String, String, String&gt; oc = Octet.fromArray(strArr);</pre>
Updated on 30-Jul-2019 22:30:25