How to call a boolean method in Java?

To call a boolean method in Java do this: myBooleanMethod().

If the boolean method is inside the same class, then you can call it directly:

public class MyClass {

  public void callingMethod() {
    if (myBooleanMethod()) {
      // do something…
    }
  }

  public boolean myBooleanMethod() {
    return true;
  }
}

If the boolean method is inside another class, then you first need to create an instance of the class and then call the method:

public class AnotherClass {

  public boolean myBooleanMethod() {
    return true;
  }
}

class MyClass {

  public void callingMethod() {
    if (new AnotherClass().myBooleanMethod()) {
      // do something…
    }
  }
}