r/learnjava • • Oct 18 '17

Fastest way to copy 2d array?

Is there a way to do it without using a for loop which just inserts indexes to a new array?

1 Upvotes

3 comments sorted by

10

u/desrtfx Oct 18 '17 edited Oct 18 '17

We are not a proxy for google.

Yet, 5 seconds of googling for "copying 2d arrays in Java" revealed a multitude of options.

https://stackoverflow.com/questions/1686425/copy-a-2d-array-in-java

You have to be aware that multi-dimensional arrays don't really exist in Java (as opposed to other languages). Such arrays are just arrays of arrays (of arrays...)

2

u/sparkas Oct 18 '17

Is there a reason you don't want to use a for-loop? Is it for an assignment?

2

u/MonochromaticPanda Oct 18 '17

I think he might just be looking for a less expensive means of doing so rather than a nested for loop