I am not very experienced and am trying to handle collisions in my hash table. However, it just skips over it and doesn't write it at all. I figured the while loop with the conditional if would take care of it... I have been playing around with it for a while now and feel like I am mixing everything up or losing my mind.
File file = new File("info.txt");
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
temp = nhash.hashing(line,maxSize);
System.out.println(line + " " + " Hash key: " + temp);
int loc = (int)temp;
if(arr[loc] != null) // I FIGURED THIS WOULD SOLVE it
{ // THE ISSUE... But IT DOESN'T
while(arr[loc] != null) {
// System.out.println("Collision at [" + loc + "] with Data Item : [" + arr[loc] + "]");
loc++;
if(loc == maxSize)
loc = 0;
}
}else {
arr[loc] = line;
// System.out.println("Data Item[" + line + "] Stored in index [" + loc + "] of array.");
key[j] = loc;
j++;
}
}