?
Solved

copy an array

Posted on 2003-03-06
3
Medium Priority
?
161 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:baseballfan45
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Accepted Solution

by:
ilmt earned 300 total points
ID: 8085970
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.

0
 

Author Comment

by:baseballfan45
ID: 8086034
i tried that and that still passes back the unsorted array though for some reason.
0
 

Author Comment

by:baseballfan45
ID: 8086055
never mind...that worked
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video teaches viewers about errors in exception handling.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question