From
SCJP 5.0 (Sierra/Bates), pg 508 ques 1
Given:
import java.util.regex.*;
class Regex2 {
public static void main(
String[] args) {
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args[1]);
boolean b = false;
while(b = m.find()) {
System.out.print(m.start() + m.group());
}
}
}
Is the while expression correct? I thought no, it needs to evaluate to a boolean, which would be == not =. But according to the answers, I am wrong.
Can someone explain why?