• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Does arraycopy create aliases?

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic