Fetch the value from an Octet Tuple in Java

Java 8Object Oriented ProgrammingProgramming

<p>To fetch the value from an Octet Tuple, use the getValueX() method. Here X is the index for which you want the value.</p><p>For example, to fetch the 5th element i.e. 4th index, use the getValueX() method as &minus;</p><pre class="result notranslate">getValue(4);</pre><p>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 &minus;</p><pre class="result notranslate">import org.javatuples.Octet;</pre><p><strong>Note</strong> &minus; Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click <strong>Project -&gt; Properties -&gt; Java Build Path -&gt; Add External</strong> Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples &minus;</p><p><strong>Steps</strong> &minus; <a href="https://www.tutorialspoint.com/how-to-run-javatuples-program-in-eclipse" rel="nofollow" target="_blank">How to run JavaTuples program in Eclipse</a></p><p>The following is an example to fetch the value from Octet Tuple in Java &minus;</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;laptop&quot;, &quot;desktop&quot;,&quot;mobile&quot;, &quot;tablet&quot;,&quot;monitor&quot;, &quot;LCD&quot;,&quot;LED&quot;, &quot;OLED&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; &nbsp; // index 0 &nbsp; &nbsp; &nbsp; System.out.println(&quot;Value 1 = &quot;+oc.getValue0()); &nbsp; &nbsp; &nbsp; // index 1 &nbsp; &nbsp; &nbsp; System.out.println(&quot;Value 2 = &quot;+oc.getValue1()); &nbsp; &nbsp; &nbsp; // index 2 &nbsp; &nbsp; &nbsp; System.out.println(&quot;Value 3 = &quot;+oc.getValue2()); &nbsp; &nbsp; &nbsp; // index 3 &nbsp; &nbsp; &nbsp; System.out.println(&quot;Value 4 = &quot;+oc.getValue3()); &nbsp; &nbsp;} }</pre><h2>Output</h2><pre class="result notranslate">Result = [laptop, desktop, mobile, tablet, monitor, LCD, LED, OLED] Value 1 = laptop Value 2 = desktop Value 3 = mobile Value 4 = tablet</pre>
raja
Updated on 30-Jul-2019 22:30:25

Advertisements