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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -