Hey,
Java’s “If. Else”:
In Java, “If. Else” is a statement, not an expression. It does not return a value and cannot assign it to a variable.
Here is an example you can follow to get the difference:
int year;
if(count == 00
year = 2014;
else
year = 2015;
Scala’s “If. Else”:
In Scala, “If. Else” is an expression. It evaluates a value i.e. returns a value. You can assign it to a variable.
val year = if (count == 0) 2014 else 2015
Scala’s “If. Else” works like Java’s Ternary Operator. You can use Scala’s “If. Else” like Java’s “If. Else” statement as shown below:
val year = 0
if( count == 0)
year = 2014
else
year = 2015