This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes System.arraycopy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "System.arraycopy?" Watch "System.arraycopy?" New topic
Author

System.arraycopy?

Igor Stojanovic
Ranch Hand

Joined: Feb 18, 2005
Posts: 58
Hi all,

i know this method gets copy of source array but it copies only rows and i would like to know is there any method similar to this one which can copy only columns for me or i have to write it for myself?

I wrote that kind of method ( not big deal anyway ) but i would like to know if there is such method in library?

P.S. i searched java api documentation but couldn't find anything...

kind regards

Igor
[ February 18, 2005: Message edited by: Igor Stojanovic ]
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
I'm not sure what you mean by rows and columns, but I don't know of any other Array copy method.
Igor Stojanovic
Ranch Hand

Joined: Feb 18, 2005
Posts: 58
Here is example what i want when i say copy aray and I specify number of columns...

This is "A" array:
1 2 3 4 5 6 7 8
9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8
9 8 7 6 5 4 3 2

when i say System.arraycopy(A, 0, B, 0, 3) I will get first 3 rows in my B array

B array :
1 2 3 4 5 6 7 8
9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8

but thats not what i want, i want method to copy first 3 columns so i can get in C array this:
1 2 3
9 8 7
1 2 3

I hope this explains what I mean

kind regards
Igor
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
No, arraycopy() works only on a single array. Note that multidimensional arrays are simply arrays of arrays -- not a single array with "rows" and "columns." You must roll your own code.

System.arraycopy() operates directly on the bytes in memory, simply copying one contiguous block of bytes to another location. Since "columns" of a two dimensional array are not contiguous in memory, it cannot be used.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: System.arraycopy?
 
Similar Threads
Calendar
Identifying GUI events
palindrome not very proficient...
Rule Round-up Game Question #108
Cannot find symbol variable