
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Fetch 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 −
getValue(4);
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 −
Steps − How to run JavaTuples program in Eclipse
The following is an example to fetch the value from Octet Tuple in Java −
Example
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()); } }
Output
Result = [laptop, desktop, mobile, tablet, monitor, LCD, LED, OLED] Value 1 = laptop Value 2 = desktop Value 3 = mobile Value 4 = tablet
Advertisements