JavaTuples equal() method

The equals() method in org.javatuples is used to check whether a TupleClass is equal to the TupleClass given as parameter. This method can be used to any tuple class object of javatuples library. It returns a boolean value that is true or false based on the equavalence of that TupleClass with existing TupleClass.

Method Declaration:

public final boolean equals(Object obj)

Syntax:



boolean result = TupleClassObject.equals(TupleClass2Object)

Parameters: This method takes TupleClass2Object as parameter where:

  • TupleClassObject– represents the JavaTuple Class object used like Unit, Quintet, Decade, etc.
  • TupleClass2Object– represents the parameter passed JavaTuple Class object used like Unit, Quintet, Decade, etc.

Return Value: This method returns true if the TupleClassObject is equal to the TupleClass2Object. Else it returns false

Below programs illustrate the various ways to use equals() method:

Program 1: Using equals() with Unit class:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Below is a Java program to use equals() 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");
  
        // Creating another Unit with one value
        Unit<String> unit1 = Unit.with("GeeksNotforGeeks");
  
        // Using equals() method
        boolean res = unit.equals(unit1);
  
        System.out.println("Is " + unit + " equal to "
                           + unit1 + " : " + res);
    }
}

chevron_right


Output:

Is [GeeksforGeeks] equal to [GeeksNotforGeeks] : false

Program 2: Using equals() with Quartet class:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Below is a Java program to use equals() method
  
import java.util.*;
import org.javatuples.Quartet;
  
class GfG {
    public static void main(String[] args)
    {
        // Creating Quartet from List
        List<String> list = new ArrayList<String>();
        list.add("GeeksforGeeks");
        list.add("A computer portal");
        list.add("for geeks");
        list.add("by Sandeep Jain");
  
        Quartet<String, String, String, String> quartet
            = Quartet.fromCollection(list);
  
        // Creating Quartet from Array
        String[] arr = { "GeeksforGeeks",
                         "A computer portal",
                         "for geeks",
                         "by Sandeep Jain" };
  
        Quartet<String, String, String, String> otherQuartet
            = Quartet.fromArray(arr);
  
        // Using equals() method
        boolean res = quartet.equals(otherQuartet);
  
        System.out.println("Is \n" + quartet + "\n equal to \n"
                           + otherQuartet + "\n : " + res);
    }
}

chevron_right


Output:

Is 
[GeeksforGeeks, A computer portal, for geeks, by Sandeep Jain]
 equal to 
[GeeksforGeeks, A computer portal, for geeks, by Sandeep Jain]
 : true

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.