I've been stuck at this problem for a few hours now. I've commented out all code thinking it was something to do with array out of bounds but this is still happening. I'm trying to read input from a file using scanner, storing data and getting that data later using the hashcode. But the hashed value keeps changing.
public static void main(String[] args)
{
//only prior code is to access data
char arr[] = new char[25];
arr = readString.toCharArray();
int y;
y = hash(arr);
}
public static int hash(char[] arr)
{
int get = arr.toString().hashCode();
System.out.println(y);
return get;
}
for the file, even with same thing on every line, there is still this problem
ex.
hello
hello
hello
i've commented out all other functions except to get the data and hash it but not sure why hashcode has differnt values. Am I using hashcode incorrectly? Is there another way to do this?
Edit* When I hash strings, inside main funcitons, value is always the same, but values that I retrieve have never been the same.
key? I don't see it defined or set, but you're using it in the first line of hash()