The following routine behaves differently on WIN XP x32, JAVA Version 7 Update 9 and on WIN7 x64, JAVA version 6 Update 32.
private int getNrOfMatches(String temp, String regex) {
String prev;
int nrOfIterations = -1;
do {
nrOfIterations++;
prev = temp;
temp = temp.replaceFirst(regex, " ");
} while (temp != prev);
return nrOfIterations;
}
replaceFirst() returns the same object if it didn't modify anything and the loop ends on WIN XP. On Win7 it goes on an endless loop as !=
will always return false because the routine returns a new object even if it didn't change anything.
Using .equals()
instead of !=
solves this issue but my question is can anyone explain this behaviour?