Skip to content
Related Articles

Related Articles

JavaTuples getSize() method

Improve Article
Save Article
  • Last Updated : 27 Aug, 2018
Improve Article
Save Article

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:




// 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);
    }
}


Output:

Size = 1

Program 2: Using getSize() with Quartet class:




// 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);
    }
}


Output:

Size = 4

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


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!