1@Override
2public int hashCode() {
3 int hash = 7;
4 hash = 31 * hash + (int) id;
5 hash = 31 * hash + (name == null ? 0 : name.hashCode());
6 hash = 31 * hash + (email == null ? 0 : email.hashCode());
7 return hash;
8}
1import java.io.*;
2public class IB {
3
4 public static void main(String args[]) {
5 String a = "100";
6 String b = "100";
7 if(a.equals(b))
8 {
9 System.out.println("Equal variables:");
10 System.out.println(a.hashCode() + "\n" + b.hashCode());
11 }
12
13 String c = "100";
14 String d = "500";
15
16 if(!c.equals(d))
17 {
18 System.out.println("\nUn-equal variables:");
19 System.out.println(c.hashCode() + "\n" + d.hashCode());
20 }
21 String Str = new String("We are learning hashCode in Java");
22 System.out.println("Hashcode for Str :" + Str.hashCode() );
23 }
24}