-
Sorting an array
I created an object called "Course" which has 4 instance variables - class code, instructor, title, and points. In the course class, I also have a compareTo method which compares the class code.
In another class, I created an array of courses and I'm trying to sort them by the class code. How do I do that? I can't call the sort or compare to method on the array, and I'm kind of stuck...
-
Re: Sorting an array
Three options. 1) write your own sort 2) Call Arrays.sort on the array 3) use a Collection, and call Collections.sort
-
Re: Sorting an array
Thanks - the problem is, when I do courseListing.sort() it says I ca't invoke sort() on the array type course[]...
-
Re: Sorting an array
-
Re: Sorting an array
One other question - is there a way to copy the contents of an array list into an array?
-
Re: Sorting an array
Take a look at API..it is very good advice to become familiar them, how to read them and how to make use of them. There are copy operations provided in both Arrays (to copy arrays) and List (the interface ArrayList implements) to convert a List to an array
List (Java Platform SE 6)