This is a question regarding casting of types in Java.
public int hashFunction(String D){
char[] Thing = D.toCharArray();
for(int i=0; i < Thing.length; i++){
index =+(int)Thing.length;
}
return index % tablesize;
}
Now how does the code work such that each content of the char array is now cast to a type int?
Java will allow you to assign
chars toints, sinceinthas a larger domain thanchar. This is known as widening:You probably want to access each element in
Thing, right? Use an enhanced for loop: