I appreciate any help with the following Java code problem:
Suppose the type of key within a hashing application being implemented is string. Design and implement a hash function which converts a key to a hash value.
-Please show test of your function by computing the hash values for the Java keywords.
-Was a key collision produced?
Expert Answer
Copyable Code:
import java.io.*;
public class HashFunExample
{
public static void main(String args[])
{
//assign the string for Else keywords
String s1 = new String(“Else”);
//assign the string for while keywords
String s2 = new String(“While”);
//assign the string for int keywords
String s3 = new String(“int”);
//assign the string for void keywords
String s4 = new String(“void”);
//display the hash code for all keywords
System.out.println(“Hash value for Else :” + s1.hashCode());
System.out.println(“Hash value for While :” + s2.hashCode());
System.out.println(“Hash value for int :” + s3.hashCode());
System.out.println(“Hash value for void :” + s4.hashCode());
}
}