JavaTuples contains() method
The contains() method in org.javatuples is used to check whether a value is present in the TupleClass, given as parameters. This method can be used for any tuple class object of the javatuples library. It returns a boolean value that is true or false based on the presence of that value in the TupleClass.
Method Declaration:
public final boolean contains(Object value)
Syntax:
boolean result = TupleClassObject.contains(X value)
Parameters: This method takes value as parameter where:
- X– represents the datatype of values in the parameter.
- TupleClassObject– represents the JavaTuple Class object used like Unit, Quintet, Decade, etc.
Return Value: This method returns true if the parameter value is present in the tuple. Else it returns false
Below programs illustrate the various ways to use contains() method:
Program 1: Using contains() with Unit class:
// Below is a Java program to create // a Unit tuple from contains() method import java.util.*; import org.javatuples.Unit; class GfG { public static void main(String[] args) { // Creating an Unit with one value Unit<String> unit = Unit.with( "GeeksforGeeks" ); // Using contains() method boolean res; String check; // for True result check = "GeeksforGeeks" ; res = unit.contains(check); System.out.println( "Is " + check + " present : " + res); // for False result check = "Geeks" ; res = unit.contains(check); System.out.println( "Is " + check + " present : " + res); } } |
Output:
Is GeeksforGeeks present : true Is Geeks present : false
Program 2: Using contains() with Decade class:
// Below is a Java program to create // a Unit tuple from contains() method import java.util.*; import org.javatuples.Decade; class GfG { public static void main(String[] args) { // Creating a Decade with 10 value Decade<String, String, String, String, String, String, String, String, String, String> decade = Decade.with( "Geeks" , "for" , "Geeks" , "A" , "Computer" , "Science" , "Portal" , "for" , "Geeks" , "RishabhPrabhu" ); // Using contains() method boolean res; String check; // for True result check = "GeeksforGeeks" ; res = decade.contains(check); System.out.println( "Is " + check + " present : " + res); // for False result check = "Geeks" ; res = decade.contains(check); System.out.println( "Is " + check + " present : " + res); } } |
Output:
Is GeeksforGeeks present : true Is Geeks present : false
Note: Similarly, it can be used with any other JavaTuple Class.
Recommended Posts:
- JavaTuples add() method
- JavaTuples with() method
- JavaTuples fromArray() method
- JavaTuples hashcode() method
- JavaTuples getLabel() method
- JavaTuples getKey() method
- JavaTuples setValue() method
- JavaTuples fromIterable() method
- JavaTuples setLabel() method
- JavaTuples setKey() method
- JavaTuples removeFromX() method
- JavaTuples setAtX() method
- JavaTuples equal() method
- JavaTuples compareTo() method
- JavaTuples addAtX() method
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.