View Single Post
Old 03-14-2005, 11:38 AM   #1 (permalink)
plague
Registered User
 
Join Date: Mar 2005
Posts: 1
plague is on a distinguished road
Sorting an array of any Comparable objects

I've been searching all over the internet for this to no avail, so thanks in advance for any help anyone can give me. Basically I have to write a class that contains a sort method which takes in an array of any Comparable Objects and returns a new array of the same type without altering the original. It has to be able to do something like this:

sortedArray = SortClass.sort(unsortedArray);

where the arrays are separate and of any type of Object. I imagine I need to create a new array and clone each object, but the problem I'm having is how do I make the new array and cast the objects to the same type as the array that was passed in? Would it be something like:

public static Object[] sort(Object[] toBeSorted) {...}

or will I have to make use of the Class class, using Class<T>? I don't really know how to do this, I was just looking around on the API spec and this seems useful.

Thanks again.
plague is offline   Reply With Quote