return an array java code example

Example 1: how do you make a method that returns an array java

public static int[] numbers()  
{  
int[] arr={5,6,7,8,9};  //initializing array  
return arr;  
}

Example 2: what is return method in java

Return method is for to be able to
continue to work what method retrieves. 
For example if it returns a String.
This means that you can use the returned
value in your code for
further processing.I guess good examples
of such methods are "getters".

Example 3: how to return array in java

import java.util.Arrays;

public class trial1{

    public static void main(String[] args){
        int[] B = numbers();
        System.out.println(Arrays.toString(B));
    }

    public static int[] numbers(){
        int[] A = {1,2,3};
        return A;
    }
}

Tags:

Java Example