Boolean Expressions
You can pass a boolean expression to a method.
System.out.println( x > y );
System.out.println( "Hello".equals("Howdy") );
A method can return a boolean.
- You can use a boolean method call anywhere you could use a boolean expression.
ifexpression.whileexpression.- Middle expression in a
for.
private static boolean booleanMethod() {
System.out.println("Hello from booleanMethod, returning true.");
return true;
}
//...
if ( booleanMethod() ) {
System.out.println("booleanMethod returned true.");
}
//...