how to hash in java code example

Example 1: java hashcode

@Overridepublic int hashCode() {    int hash = 7;    hash = 31 * hash + (int) id;    hash = 31 * hash + (name == null ? 0 : name.hashCode());    hash = 31 * hash + (email == null ? 0 : email.hashCode());    return hash;}

Example 2: hashset in java

// java hashmap example
import java.util.HashMap;
public class HashMapExample 
{
   public static void main(String[] args) 
   {
      HashMap<Integer, String> hm = new HashMap<Integer, String>();
      // add elements
      hm.put(10,"Apple");
      hm.put(20,"Banana");
      hm.put(30,"Cherry");
      hm.put(40,"Dragonfruit");
      // print HashMap elements
      System.out.println("HashMap elements: " + hm);
   }
}

Example 3: hashset in java

// java hashset example.
import java.util.HashSet;
public class HashSetExample
{
   public static void main(String[] args)
   {
      HashSet<String> hs = new HashSet<>();
      hs.add("Banana");
      hs.add("Orange");
      hs.add("Apple");
      hs.add("Pineapple");
      hs.add("Mango");
      System.out.println(hs);
   }
}