A typed method can only return one value. (Yes, a method MAY have several return statements but only one of them will execute depending on the condition.)

Sometimes we need to return more than one value. To get around the limitation above we can return one array, that stores multiple values. The array can contain numerical values or Strings (not the same array of course as an array must contain the same datatype throughout)

One dimensional array

Here is a two-class program – it has a UI class and a manager class.  The methods in the manager class generate an array of six random numbers which is passed back to the UI class. The UI class in turn passes the array to a method that prints the values to the monitor. 

NOTE: You will notice that the only real difference between returning a single value and returning an array are the square brackets [  ]

Click here

Two dimensional array

A two class program that searches for a value within a two dimensional array. The array is passed to a manager class with a search method. If found, the co-ordinates are returnded via a one dimensional array.

NOTE: If the value appears more than once in the array it will report the last occurance of the value only.

Click here