int MATCH_LENGTH = 0;
int FINAL_MATCH_LENGTH = 0;
int FINAL_MATCH_POS = 0;
while (window.contains(next)) {
int MATCH_POS = window.indexOf(next);
boolean nextMatches = true;
while (nextMatches = true) {
int index = window.indexOf(next);
index++;
int positionOfNext = fileArray.indexOf(next);
positionOfNext++;
MATCH_LENGTH++;
char afterNext = fileArray.get(positionOfNext);
char afterNextInWindow = window.get(index);
if (afterNext != afterNextInWindow) {
nextMatches = false;
if (MATCH_LENGTH > FINAL_MATCH_LENGTH) {
FINAL_MATCH_POS = MATCH_POS;
FINAL_MATCH_LENGTH = MATCH_LENGTH;
MATCH_LENGTH = 0;
}
window.remove(window.indexOf(next));
}
}
}
I am running into an infinite loop here. I think it is because of the nextMatches boolean variable. However, I am not sure how that affects the program, as I have the condition for the while loop as while (window.contains(next)). However, I am removing the occurrences of next one by one, so eventually while (window.contains(next)) will have to return false and the while loop will have to break. My reasoning here might be flawed though with the remove line window.remove(window.indexOf(next));.
Or is some other part of my reasoning flawed?
The problem is here
while (nextMatches = true)try put instead