Fetch the value from an Octet Tuple in Java

To fetch the value from an Octet Tuple, use the getValueX() method. Here X is the index for which you want the value.

For example, to fetch the 5th element i.e. 4th index, use the getValueX() method as −


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 −

import org.javatuples.Octet;

Note − Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples −

StepsHow to run JavaTuples program in Eclipse

The following is an example to fetch the value from Octet Tuple in Java −


import org.javatuples.Octet;
import java.util.*;
public class Demo {
   public static void main(String[] args) {
      String[] strArr = {"laptop", "desktop","mobile", "tablet","monitor", "LCD","LED", "OLED"};
      Octet<String, String, String, String, String, String, String, String> oc = Octet.fromArray(strArr);
      System.out.println("Result = " + oc);
      // index 0
      System.out.println("Value 1 = "+oc.getValue0());
      // index 1
      System.out.println("Value 2 = "+oc.getValue1());
      // index 2
      System.out.println("Value 3 = "+oc.getValue2());
      // index 3
      System.out.println("Value 4 = "+oc.getValue3());


Result = [laptop, desktop, mobile, tablet, monitor, LCD, LED, OLED]
Value 1 = laptop
Value 2 = desktop
Value 3 = mobile
Value 4 = tablet