JavaTuples setValue() method
Last Updated :
27 Aug, 2018
The setValue() method in org.javatuples is used to set the value in the LabelValueClassObject or KeyValueClassObject. This method can be used with only LabelValue class or KeyValue class of javatuples library. It returns another ClassObject with the value as the element passed as the parameter, and the key or label from the previous ClassObject.
LabelValue.setValue()
Method Declaration:
public <X> LabelValue<A, X> setValue(X value)
Syntax:
LabelValue<A, B> LabelValueClassObject = LabelValue.setValue(X value)
Return Value: This method returns another LabelValueClassObject with the value as the element passed as the parameter, and the label from the previous LabelValueClassObject.
Below is the program that will illustrate the various ways to use setValue() method in LabelValue Class:
Example:
import java.util.*;
import org.javatuples.LabelValue;
class GfG {
public static void main(String[] args)
{
LabelValue<Integer, String> lv
= LabelValue.with(Integer.valueOf( 1 ),
"A computer science portal" );
LabelValue<Integer, Integer> lv1 = lv.setValue(Integer.valueOf( 2 ));
System.out.println(lv1);
}
}
|
Output:
[1, 2]
KeyValue.setValue()
Method Declaration:
public <X> KeyValue<A, X> setValue(X value)
Syntax:
KeyValue<A, B> KeyValueClassObject = KeyValue.setValue(X value)
Return Value: This method returns another KeyValueClassObject with the value as the element passed as the parameter, and the key from the previous KeyValueClassObject.
Below is the program that will illustrate the various ways to use setValue() method in KeyValue Class:
Example:
import java.util.*;
import org.javatuples.KeyValue;
class GfG {
public static void main(String[] args)
{
KeyValue<Integer, String> kv
= KeyValue.with(Integer.valueOf( 1 ),
"A computer science portal" );
KeyValue<Integer, String> kv1 = kv.setValue( "GeeksforGeeks" );
System.out.println(kv1);
}
}
|
Output:
[1, GeeksforGeeks]
Share your thoughts in the comments
Please Login to comment...