Java Reference
In-Depth Information
Use the
clone
method to copy the elements of an array.
double[] prices = (double[]) data.clone();
The
clone
method (which we will more closely study in
Chapter 10
) has the return
type
Object
. You need to cast the return value of the clone method to the
appropriate array type such as
double[]
.
Figure 7
Two References to the Same Array
Figure 8
Cloning an Array
311