M9A
M9A

Reputation: 3276

How to copy a row from a 2d array to another

Hi I have a large 2D array (sample[1000][10]). I was wondering, how can I copy over the last row (1000) into a temp 2d array (temp[1][10])?

EDIT: I have tried the following but I was wondering if there is a much quicker code:

for (int i = 0; i < 10; i++){
temp[0][i] = sample[sample.length - 1][i];
}

Upvotes: 1

Views: 2912

Answers (1)

Dan D.
Dan D.

Reputation: 32391

Use System.arraycopy:

System.arraycopy(sample[999], 0, temp[0], 0, 10);

Upvotes: 5

Related Questions