88
How to return an array in Java
In this section, we are going to learn how to return an array in Java.
Remember:
- A method can return a reference to an array.
- The return type of a method must be declared as an array of the correct data type.
Example 1
In the following example, the method returns an array of integer type.
Output:
Example 2
In the following example, the method returns an array of double type.
Output:
Example 3
In the following example, method returns an array of object type.
Output:
Next TopicJava Tutorial