Java-Returning Arrays From Method

Returning Arrays From Method

A method may also return an array. For example, in the following program, the method returnData( ) returns an array.

Program

sdsd

Program Source

class Data {

    int[] returnData()
    {
        return new int[]{20,40,60,80};
    }
}

public class Javaapp {

    public static void main(String[] args) {
   
        Data da = new Data();
        int[] getData = da.returnData();
   
        for(int x : getData)
        {
            System.out.println(x);
        }
    }
}

Leave a Comment