JavaTuples hashcode() method

The hashCode() method in org.javatuples method returns the hash code for the JavaTuple class object. The hashcode is always the same if the object doesn’t change. Hashcode is a unique code generated by the JVM at time of object creation. It can be used to perform some operation on hashing related algorithm like hashtable, hashmap etc. An object can also be searched with this unique code.

Method Declaration:

public final int hashCode()

Syntax:



int code = TupleClassObject.hashCode()

Here TupleClassObject represents the JavaTuple Class used like Unit, Quartet, Decade, KeyValue, etc.

Returns: It returns an integer value which represents hashCode value for this TupleClassObject.

Below program illustrates hashcode() method of TupleClassObject:
Program 1: Get the hash code of a Quartet Class object.

filter_none

edit
close

play_arrow

link
brightness_4
code

// Below is a Java program to use hashCode()
// with a LabelValue tuple
  
import java.util.*;
import org.javatuples.Quartet;
  
class GfG {
    public static void main(String[] args)
    {
        // Creating a Quartet with 4 values
        Quartet<Integer, String, String, Double> quartet
            = Quartet.with(Integer.valueOf(1),
                           "GeeksforGeeks",
                           "A computer portal",
                           Double.valueOf(20.18));
  
        // Using the hashCode() method
        int code = quartet.hashCode();
  
        // Printing the returned hashCode
        System.out.println(code);
    }
}

chevron_right


Output:

-1296686340

Program 2: Get the hash code of a LabelValue Class object.

filter_none

edit
close

play_arrow

link
brightness_4
code

// Below is a Java program to use hashCode()
// with a LabelValue tuple
  
import java.util.*;
import org.javatuples.LabelValue;
  
class GfG {
    public static void main(String[] args)
    {
        // Creating a LabelValue object
        LabelValue<Integer, String> lv
            = LabelValue.with(Integer.valueOf(1),
                              "A computer science portal");
  
        // Using the hashCode() method
        int code = lv.hashCode();
  
        // Printing the returned hashCode
        System.out.println(code);
    }
}

chevron_right


Output:

-1587127699

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.