copy an array

I am passing an object array into a function and I want to return a sorted copy of the array without altering the original.  I dont want to copy the actual objects in the array, I just need two arrays pointing to the same objects, just in different orders.  So the original array will remain unchanged, but the sorted array will point to the same objects at the one I passed into the function, but it will point to them in a sorted manner.  How do I go about creating and assinging the array which will hold the sorted order?  I already have an effective sorting algorithm, I just need to figure out how to define and assign the sorted array such that it will point to the same objects, yet when I run the sorting process, it will not alter the original array as well.  Thanks
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

java.lang.System.arraycopy is an efficient way to make a copy of an array. The copy will be a separate array, but pointing to the same objects. (You are copying the references to the objects) You can then move the objects around in the copied array (eg foo[3] = x;) without affecting the original array.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
baseballfan45Author Commented:
i tried that and that still passes back the unsorted array though for some reason.
baseballfan45Author Commented:
never mind...that worked
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.