Java Reference
In-Depth Information
The length method differs from the println method in another way: it has an
output. We say that the method returns a value, namely the number of characters in
the string. You can store the return value in a variable:
The return value of a method is a result that the method has computed for use by the
code that called it.
int n = greeting.length();
You can also use the return value as a parameter of another method:
System.out.println(greeting.length());
Figure 5
Passing a Parameter to the println Method
40
41
Figure 6
Invoking the length Method on a String Object
Search WWH ::




Custom Search