Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 3rd, 2005, 12:52 PM   #1
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 843
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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.
titaniumdecoy is offline   Reply With Quote
Old Dec 3rd, 2005, 1:56 PM   #2
robrosas
Newbie
 
robrosas's Avatar
 
Join Date: Nov 2005
Location: Puerto Rico
Posts: 12
Rep Power: 0 robrosas is an unknown quantity at this point
Talking Try this ...

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
robrosas is offline   Reply With Quote
Old Dec 3rd, 2005, 2:56 PM   #3
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 843
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
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.
titaniumdecoy is offline   Reply With Quote
Old Dec 3rd, 2005, 3:32 PM   #4
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 294
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
System.arraycopy()
andro is offline   Reply With Quote
Old Dec 3rd, 2005, 3:36 PM   #5
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 843
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
I tried that but it doesn't work. Using the loop works fine, so never mind.
titaniumdecoy is offline   Reply With Quote
Old Dec 3rd, 2005, 3:44 PM   #6
andro
Professional Programmer
 
Join Date: Oct 2005
Location: California
Posts: 294
Rep Power: 3 andro is on a distinguished road
Send a message via AIM to andro
System.arraycopy(array1, 0, array2, 0, array1.length);

That should (and will) work.
andro is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC