Use the return keyword to exit from a method.
public void someMethod() {
//… a bunch of code …
if (someCondition()) {
return;
}
//… otherwise do the following…
}
From the Java Tutorial that I linked to above:
Any method declared void doesn’t return a value. It does not need to contain a return statement, but it may do so. In such a case, a return statement can be used to branch out of a control flow block and exit the method and is simply used like this:
return;
To add to the other answers, you can also exit a method by throwing an exception manually:
throw new Exception();