Is this correct?
<c:if test="${theBooleanVariable == false}">It's false!</c:if>
Or could I do this?
<c:if test="${!theBooleanVariable}">It's false!</c:if>
parseBoolean(String s) − This method accepts a String variable and returns boolean. If the given string value is "true" (irrespective of its case) this method returns true else, if it is null or, false or, any other value it returns false.
An if statement checks a boolean value and only executes a block of code if that value is true . To write an if statement, write the keyword if , then inside parentheses () insert a boolean value, and then in curly brackets {} write the code that should only execute when that value is true .
To display Boolean type, firstly take two variables and declare them as boolean. val1 = true; Now, use if statement to check and display the Boolean true value. if(val1) System.
A Boolean expression is a Java expression that returns a Boolean value: true or false .
You can have a look at the EL (expression language) description here.
Both your code are correct, but I prefer the second one, as comparing a boolean to true
or false
is redundant.
For better readibility, you can also use the not
operator:
<c:if test="${not theBooleanVariable}">It's false!</c:if>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With