Home » How to Return an Array in Java

How to Return an Array in Java

by Online Tutorials Library

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:

How to return an array in Java

Example 2

In the following example, the method returns an array of double type.

Output:

How to return an array in Java

Example 3

In the following example, method returns an array of object type.

Output:

How to return an array in Java


Next TopicJava Tutorial

You may also like