The return statement in Java is always closely related to the method. The return statement is always used in the method. It has two functions. One is to return the value of the specified type of the method (this value is always determined), and the other is to end the execution of the method (just a return statement).
In various articles of return statements, most of them only introduce the methods used for return statements with return values (non-void return values). However, the use of return statements in the vodi return value method is rarely or not introduced.
The return statement is used in methods that are not void return value types. It can not only return the basic type, but also return objects (including user-defined classes).
1: The return statement is always used in the method and has two functions:
One is to return the value of the specified type of the method (this value is always determined).
One is to end the execution of the method (just a return statement).
two:
Example 1 -- Return a String
private String gets(){ String s = "qw789" ; return s ; }
Example 2 -- End the program
private void gets(String s ){ if ( s == null ){ return ; } ( "haha" ) ; }
The above introduces the usage of return in Java through two examples, hoping it will be helpful to everyone.