JavaTuples setLabel() method

The setLabel() method in org.javatuples is used to set the label of the LabelValue Class object. This method can be used with only LabelValue class object of javatuples library. It returns another LabelValueClassObject with the Label as the element passed as the parameter, and the value from the previous LabelValueClassObject.

Method Declaration:

public <X> LabelValue<X, B> setLabel(X label)

Syntax:



LabelValue<X, B> LabelValueClassObject = LabelValue.setLabel(X label)

Return Value: This method returns another LabelValueClassObject with the Label as the element passed as the parameter, and the value from the previous LabelValueClassObject.

Below are programs that will illustrate the various ways to use setLabel() method:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Below is a Java program to set
// label in a LabelValue pair
  
import java.util.*;
import org.javatuples.LabelValue;
  
class GfG {
    public static void main(String[] args)
    {
        // Creating a LabelValue object
        LabelValue<Integer, String> lv
            = LabelValue.with(Integer.valueOf(1),
                              "A computer science portal");
  
        // Using setLabel() method
        LabelValue<String, String> lv1 = lv.setLabel("GeeksforGeeks");
  
        // Printing the returned LabelValue
        System.out.println(lv1);
    }
}

chevron_right


Output:

[GeeksforGeeks, A computer science portal]

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Below is a Java program to set
// label in a LabelValue pair
  
import java.util.*;
import org.javatuples.LabelValue;
  
class GfG {
    public static void main(String[] args)
    {
        // Creating a LabelValue object
        LabelValue<Integer, String> lv
            = LabelValue.with(Integer.valueOf(1),
                              "1");
  
        // Using setLabel() method
        LabelValue<String, String> lv1 = lv.setLabel("One");
  
        // Printing the returned LabelValue
        System.out.println(lv1);
    }
}

chevron_right


Output:

[One, 1]


My Personal Notes arrow_drop_up

Technical Content Engineer at GeeksForGeeks

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.