Java Data Type Tutorial - Byte hashCode() example








Byte hashCode() returns a hash code for this Byte.

It is equal to the result from intValue()

Syntax

hashCode has the following syntax.

public int hashCode()

Overrides

hashCode in class Object

Return

hashCode returns a hash code value for this Byte

Example

In the following code shows how to use Byte.hashCode() method.

public class Main {
//from  ww w.  j  ava 2 s .c  o  m
   public static void main(String[] args) {
      Byte b1 = new Byte("100");
      Byte b2 = new Byte("-100");

      int i1 = b1.hashCode();
      int i2 = b2.hashCode();

      String str1 = "Hashcode of Byte " + b1 + " is " + i1;
      String str2 = "Hashcode of Byte " + b2 + " is " + i2;

      System.out.println( str1 );
      System.out.println( str2 );
   }
}

The code above generates the following result.