- JavaTuples - Discussion
- JavaTuples - Useful Resources
- JavaTuples - Quick Guide
- JavaTuples - Decade using Ennead
- JavaTuples - Ennead using Octet
- JavaTuples - Octet using Septet
- JavaTuples - Septet using Sextet
- JavaTuples - Sextet using Quintet
- JavaTuples - Quintet using Quartet
- JavaTuples - Quartet using Triplet
- JavaTuples - Triplet using Pair
- JavaTuples - Pair using Unit
- JavaTuples - KeyValue Class
- JavaTuples - LabelValues Class
- JavaTuples - Decade Class
- JavaTuples - Ennead Class
- JavaTuples - Octet Class
- JavaTuples - Septet Class
- JavaTuples - Sextet Class
- JavaTuples - Quintet Class
- JavaTuples - Quartet Class
- JavaTuples - Triplet Class
- JavaTuples - Pair Class
- JavaTuples - Unit Class
- JavaTuples - Checking Elements
- JavaTuples - Iteration
- JavaTuples - Conversion
- JavaTuples - Remove Elements
- JavaTuples - Add Elements
- JavaTuples - Set Values
- JavaTuples - Get Values
- JavaTuples - Create Tuples
- JavaTuples - Environment Setup
- JavaTuples - Overview
- JavaTuples - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
JavaTuples - LabelValues Class
Introduction
The org.javatuples.LabelValue class represents a Tuple with two elements with positions 0 and 1 renamed as "label" and "value", respectively.
Class Declaration
Following is the declaration for org.javatuples.LabelValue class −
pubpc final class LabelValue<A,B> extends Tuple implements IValue0<A>, IValue1<B>
Class Constructor
Sr.No. | Constructor & Description |
---|---|
1 | LabelValue(A value0, B value1) This creates a LabelValue Tuple. |
Class Methods
Sr.No. | Method & Description |
---|---|
1 | static <X> LabelValue<X,X> fromArray(X[] array) Create tuple from array. |
2 | static <X> LabelValue<X,X> fromCollection(Collection<X> collection) Create tuple from collection. |
3 | static <X> LabelValue<X,X> fromIterable(Iterable<X> iterable) Create tuple from iterable. |
4 | static <X> LabelValue<X,X> fromIterable(Iterable<X> iterable, int index) Create tuple from iterable, starting from the specified index. |
5 | A getLabel() Return the label. |
6 | int getSize() Return the size of the tuple. |
7 | A getValue() Returns the value of the tuple. |
8 | <X> LabelValue<X,B> setLabel(X label) set the label and return the tuple. |
9 | <X> LabelValue<A,Y> setValue(Y value) set the value and return the tuple. |
10 | static <A,B> LabelValue<A,B> with(A value0, B value1) Create the tuple using given value. |
Methods inherite
This class inherits methods from the following classes −
org.javatuples.Tuple
Object
Example
Let s see LabelValue Class in action. Here we ll see how to use various methods.
Create a java class file named TupleTester in C:>JavaTuples.
File: TupleTester.java
package com.tutorialspoint; import java.util.ArrayList; import java.util.List; import org.javatuples.LabelValue; pubpc class TupleTester { pubpc static void main(String args[]){ LabelValue<Integer, Integer> labelValue = LabelValue.with(5,6); System.out.println(labelValue); List<Integer> pst = new ArrayList<>(); pst.add(1); pst.add(2); Integer label = labelValue.getLabel(); System.out.println(label); Integer value = labelValue.getValue(); System.out.println(value); LabelValue<Integer, Integer> labelValue1 = LabelValue.fromCollection(pst); System.out.println(labelValue1); } }
Verify the result
Compile the classes using javac compiler as follows −
C:JavaTuples>javac -cp javatuples-1.2.jar ./com/tutorialspoint/TupleTester.java
Now run the TupleTester to see the result −
C:JavaTuples>java -cp .;javatuples-1.2.jar com.tutorialspoint.TupleTester
Output
Verify the Output
[5, 6] 5 6 [1, 2]Advertisements