sunder sunder - 1 year ago 60
Java Question

Return value of assignment operation in java

I encountered a statement in java

while ((line = reader.readLine()) != null) {

How assignment operations return value in Java? As the statement we are checking is
and comparing it with
. Because
will return string , how exactly we are checking for

Answer Source

The assignment operator in Java returns the assigned value (like it does, e.g., in ). So here, readLine() will be executed, and it's return value stored in line. That value is then checked against null, and if it is null, the loop will terminate.