Hi, I need some enlightenment with copying arrays in JAVA from some of ya seasoned lots.

I have this 2d array , twoDarray[10][6] and another 1d array oneDarray[1,2,3,4,5,6]. I'd like to copy the 1d array into the 4th row of the 2d array.Suggestion please. Thnx in advance.

Recommended Answers

All 2 Replies

The twoDArray in your case is just an array of size 10 with each slot referring to a integer array i.e. two dimensional arrays in Java are just an array of arrays. Hence you can either use twoDArray[3] = oneDArray; or System.arraycopy if you don't want modifications in the original oneDArray to be reflected in twoDArray. Also read this.

thnx for the valuable input...appreciate it..muah.

The twoDArray in your case is just an array of size 10 with each slot referring to a integer array i.e. two dimensional arrays in Java are just an array of arrays. Hence you can either use twoDArray[3] = oneDArray; or System.arraycopy if you don't want modifications in the original oneDArray to be reflected in twoDArray. Also read this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.