I wanted to optimize my code, so instead of copying my entire char array for each iteration in the alphabet, I opted to do the copying beforehand and then I'd just add chars into the copy.
E.g.:
copy "lord" (i=0)
modify the first letter (aord, bord, cord &c)
copy "lord" (i=1)
modify the second letter (lard, lbrd, lcrd &c)
&c
for (int i = 0; i < wordLength; i++) {
Word moddedWord = new Word(Arrays.copyOf(temp.word.content, wordLength));
for (int c = 0; c < alphabetLength; c++) {
if (alphabet[c] != temp.word.content[i]) {
// Word moddedWord = new Word(Arrays.copyOf(temp.word.content, wordLength));
moddedWord.content[i] = alphabet[c];
Word res = WordList.Contains(moddedWord);
if (res != null && WordList.MarkAsUsedIfUnused(res)) {
WordRec wr = new WordRec(res, temp);
q.Put(wr);
}
}
}
}
However, when I do this small change, my program doesn't work, when it used to when I instead used the commented line for copying. I've debugged this for hours on end now and I can find nothing that changes this, I've tried various forms of copying, I've tried storing the "original" word as a String and then converting it to a char array when I need to copy it, nothing seems to work. Oh by the way, "Word" is just a wrapper for char[] (Word.content is a char[] field).