Java ternary operator logic explanation -
can please explain line of java code doing?
public string gettitlenavcontainer(boolean isthislandingpage) { return isthislandingpage ? stringutils.empty : "title-nav-container"; }
i can see doing wondering how modify if landing page 1 thing otherwise else.
thanks help.
the above line called ternary operator
ternary operator
takes 3 parameter , sudo code is
condition ? statement1 : statement2
condition: part should have valid conditional statement , should return boolean value
statement1: if condition true
statement1
execute
statement2: if condition false
statement2
execute
now @ code block
public string gettitlenavcontainer(boolean isthislandingpage) { return isthislandingpage ? stringutils.empty : "title-nav-container"; }
if isthislandingpage
true
stringutils.empty
execute else title-nav-container
execute
for quick understanding, convert code if-else
statement
if (isthislandingpage) { return stringutils.empty; } else { return title-nav-container; }
Comments
Post a Comment