This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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.
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
Joined: Sep 29, 2000
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?
Joined: Oct 06, 2000
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?