This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Create Copy of Java Array

To make a copy of an existing Java® array, use subscript indexing. For example, create and initialize origArray.

origArray = javaArray('java.lang.Double',3,4);
for m = 1:3
   for n = 1:4
      origArray(m,n) = java.lang.Double((m*10)+n);
   end
end
origArray
origArray =

  java.lang.Double[][]:

    [11]    [12]    [13]    [14]
    [21]    [22]    [23]    [24]
    [31]    [32]    [33]    [34]

Copy the entire contents to newArray.

newArray = origArray(:,:)
newArray =

  java.lang.Double[][]:

    [11]    [12]    [13]    [14]
    [21]    [22]    [23]    [24]
    [31]    [32]    [33]    [34]

Change elements of newArray.

newArray(3,:) = java.lang.Double(0)
newArray =

  java.lang.Double[][]:

    [11]    [12]    [13]    [14]
    [21]    [22]    [23]    [24]
    [ 0]    [ 0]    [ 0]    [ 0]

The values in origArray do not change.

origArray
origArray =

  java.lang.Double[][]:

    [11]    [12]    [13]    [14]
    [21]    [22]    [23]    [24]
    [31]    [32]    [33]    [34]

Related Topics