aspose file tools*
The moose likes Beginning Java and the fly likes Does arraycopy create aliases? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Does arraycopy create aliases?" Watch "Does arraycopy create aliases?" New topic
Author

Does arraycopy create aliases?

michael bradly
Ranch Hand

Joined: Oct 06, 2000
Posts: 112
I have an array of objects that I am copying into another array. Each of the arrays will be sorted in a different manner. However, both arrays seem to be using the same method since they are sorting the exact same way even though they are using different sort methods.
I was wondering if arraycopy is creating an alias of the two arrays, and that this might be the problem I am having.

Regards, Michael
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Are you doing a shallow copy or a deep copy? How are you doing the "copy"?
Why don't you show us your code.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Never mind. I actually READ your question, and you really did say that you used System.arraycopy().
So you should end up with two separate arrays, unrelated to each other, but with references that are pointing at the same objects.
What are you using to do the sort?
michael bradly
Ranch Hand

Joined: Oct 06, 2000
Posts: 112
Here is the code in question. I'm wondering that since they are references to the same objects, must I create a comparableTo method to differentiate? I am trying to do a selection sort and a bubble sort.
I am working on this project with a classmate and I decided to create an array of objects and he worked on an array of int's to sort. His worked, so I used his code for the sorting process.


Originally posted by Cindy Glass:
So you should end up with two separate arrays, unrelated to each other, but with references that are pointing at the same objects.
What are you using to do the sort?

[ April 22, 2002: Message edited by: Jim Yingst ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does arraycopy create aliases?
 
Similar Threads
arraycopy
Searching, copying, and concatenating arrays
How do to use ArrayCopy?
merging multiple arrays, unchecked warnings
how to append two string ararys?