DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   JAVA: copying 1d array's value into a specific row of a 2d array (http://www.daniweb.com/forums/thread163597.html)

RabbitruN Dec 22nd, 2008 2:20 pm
JAVA: copying 1d array's value into a specific row of a 2d array
 
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.

~s.o.s~ Dec 22nd, 2008 2:33 pm
Re: JAVA: copying 1d array's value into a specific row of a 2d array
 
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.

RabbitruN Dec 22nd, 2008 3:12 pm
Re: JAVA: copying 1d array's value into a specific row of a 2d array
 
thnx for the valuable input...appreciate it..muah.

Quote:

Originally Posted by ~s.o.s~ (Post 762641)
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.



All times are GMT -4. The time now is 12:23 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC