9.4 Two-Dimensional Arrays Passed to and Returned from Methods

Writing methods that take two-dimensional arrays as parameters and/or return two-dimensional arrays is similar to working with single-dimensional arrays.

The syntax for a method that accepts a two-dimensional array as a parameter is the following:

returnType methodName( arrayType [ ][ ] arrayParameterName )

The syntax for a method that returns a two-dimensional array is the following:

returnArrayType [ ][ ] methodName( parameterList )

The caller of the method passes the argument list and assigns the return value to a reference to a two-dimensional array of the appropriate data type.

Combining both possibilities, the syntax for a method that accepts a two-dimensional array as a ...

Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.