JavaTuples getSize() method
The getSize() method in org.javatuples is used to fetch the size of the TupleClassObject. That is, it is used to fetch the number of values present in the TupleClassObject. This method can be used to any tuple class object of the javatuples library. It returns a integer value equal to the number of the elements present in the TupleClassObject.
Method Declaration:
public abstract int getSize()
Syntax:
int size = TupleClassObject.getSize()
Here TupleClassObject represents the JavaTuple Class object used like Unit, Quintet, Decade, etc.
Parameters: This method do not takes any parameter.
Return Value: This method returns the number of elements present in the TupleClassObject, in integer format.
Below programs illustrate the various ways to use getSize() method:
Program 1: Using getSize() with Unit class:
import java.util.*;
import org.javatuples.Unit;
class GfG {
public static void main(String[] args)
{
Unit<String> unit = Unit.with( "GeeksforGeeks" );
int size = unit.getSize();
System.out.println( "Size = " + size);
}
}
|
Output:
Size = 1
Program 2: Using getSize() with Quartet class:
import java.util.*;
import org.javatuples.Quartet;
class GfG {
public static void main(String[] args)
{
Quartet<String, String, String, String> quartet
= Quartet.with( "GeeksforGeeks" ,
"A computer portal" ,
"for geeks" ,
"by Sandeep Jain" );
int size = quartet.getSize();
System.out.println( "Size = " + size);
}
}
|
Output:
Size = 4
Note: Similarly, it can be used with any other JavaTuple Class.
Last Updated :
27 Aug, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...