![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
Another array problem
I'm trying to copy an array to another variable so that changes to the new array do not affect the original. The array in question stores byte values, not objects. I tried using clone() but for some reason it doesn't seem to make any difference. Is there an easy way to do this? Thanks.
|
|
|
|
|
|
#2 |
|
Newbie
Join Date: Nov 2005
Location: Puerto Rico
Posts: 12
Rep Power: 0
![]() |
for (int i=0 ; i < arrayToCopy.size();i++){
DestArray[i]=arrayToCopy[i];
}And then manipulate the new DestArray that contains the same as the original.
__________________
From P.R. to the World!! RoBeRt |
|
|
|
|
|
#3 |
|
Expert Programmer
|
Thanks, although isn't there any way to do this without using a loop? I'm looking for the fastest and most concise method possible. If not, I'll just use this.
|
|
|
|
|
|
#4 |
|
Professional Programmer
|
System.arraycopy()
|
|
|
|
|
|
#5 |
|
Expert Programmer
|
I tried that but it doesn't work. Using the loop works fine, so never mind.
|
|
|
|
|
|
#6 |
|
Professional Programmer
|
System.arraycopy(array1, 0, array2, 0, array1.length); That should (and will) work. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|