Please enable JavaScript to use CodeHS

CodeHS Glossary

Return statement Java

The `return` statement exits a method and returns a value. One valuable aspect of methods is that they can perform some computations and return the result. The following code has a helper method that returns “hello world” when the method is called. The return value is stored into a variable, which is then printed: ``` public void run() { String textToPrint = getHello(); System.out.println(textToPrint); } private String getHello() { String str = "hello world"; return str; } ``` Methods can return many different types of results, such as Strings, ints, doubles, and more. If no value gets returned from a method, the method return type is `void`.