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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Below is a Java program to use getSize() 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 getSize() method
        int size = unit.getSize();
  
        System.out.println("Size = " + size);
    }
}

chevron_right


Output:

Size = 1

Program 2: Using getSize() with Quartet class:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Below is a Java program to use getSize() method
  
import java.util.*;
import org.javatuples.Quartet;
  
class GfG {
    public static void main(String[] args)
    {
        // Creating an Quartet with four values
  
        Quartet<String, String, String, String> quartet
            = Quartet.with("GeeksforGeeks",
                           "A computer portal",
                           "for geeks",
                           "by Sandeep Jain");
  
        // Using getSize() method
        int size = quartet.getSize();
  
        System.out.println("Size = " + size);
    }
}

chevron_right


Output:

Size = 4

Note: Similarly, it can be used with any other JavaTuple Class.



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.