Wednesday 6 September 2017

Check Null with ternary operator

At its most basic, the ternary operator, also known as the conditional operator, can be used as an alternative to the Java if/then/else syntax, but it goes beyond that, and can even be used on the right hand side of Java statements.


Example:-

<c:out value="<%=item.getMiddleName()!=null?item.getFirstName()+' '+item.getMiddleName()+' '+item.getLastName():item.getFirstName()+' '+item.getLastName()%>"></c:out>

No comments:

Post a Comment