Java - if elsif else statements

by
Jeremy Canfield |
Updated: May 25 2024
| Java articles
An if else if statement in a Java bean/class has the following structure.
if (comparison) {
--do something--
}
else if (comparison) {
--do something--
}
else {
--do something
}
For example.
if (foo == 10) {
System.out.println("foo equals 10");
}
else if (foo == 20) {
System.out.println("foo equals 20");
}
else {
System.out.println("foo does not equal 10 or 20");
}
Equals |
if (foo == "bar") # string if (foo == 12345) # integer if (foo == true) # boolean |
Equals args | if (args[0].equals("foo")) |
If variable is empty / null | if (foo == null) |
Did you find this article helpful?
If so, consider buying me a coffee over at