• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does arraycopy create aliases?

 
michael bradly
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you doing a shallow copy or a deep copy? How are you doing the "copy"?
Why don't you show us your code.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic