Skip to content
Related Articles

Related Articles

Improve Article

JavaTuples getSize() method

  • Last Updated : 27 Aug, 2018

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:

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

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
Recommended Articles
Page :