- To pass an array as an argument to a method, specify the name of the array without
brackets.
int hourlyTemperatures[] = new int[24];
modifyArray( hourlyTemperatures );
passes array hourlyTemperatures to method modifyArray.
- Although arrays are passed call-by-reference, individual elements of primitive data
types are passed call-by-value.
- When an element of an array is not a primitive data type (e.g., an object or another
array), then its too is passed call-by-reference.
These are not new rules. They merely are applications of the 1 rule:
Primitive data types are passed call-by-value (copied); objects and arrays are
passed call-by-reference.
- To set up a method to receive an array, declare it in its parameter list.
public void modifyArray( int b[] );
This indicates that the method expects to receive an array of int.
- The accompanying applet illustrates the difference between passing an array and passing
an array element which is a primitive data type.