Bootstrap FreeKB - Java - if elsif else statements
Java - if elsif else statements

Updated:   |  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");
}

 

Following are common if statements.

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 Buy Me A Coffee



Comments


Add a Comment


Please enter 08b9e7 in the box below so that we can be sure you are a human.