Author
ArrayList question
V Bose
Ranch Hand
Joined: Jul 10, 2003
Posts: 113
How do I stuff all the elements of a double array into a Collection and then sort them, in Java 1.5 The following throws a runtime class cast exception... . . . double[] mArray; . . . List mList = new ArrayList (Arrays.asList(mArray)); Collections.sort(mArray)
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
Indeed. Why not use the static sort() methods in the java.util.Arrays class instead?
[Jess in Action] [AskingGoodQuestions]
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
First, I'd like to say that Ernest's suggestion is the best since you don't have to create any extra objects. With that said, I'm surprised that your code compiles! Collections.sort() takes a List argument not an array. You can fix this by doing instead. HTH Layne
Java API Documentation
The Java Tutorial
Mark Spritzler
ranger
Sheriff
Joined: Feb 05, 2001
Posts: 17233
posted Jul 21, 2005 09:49:00
0
"V Bose"- Welcome to the JavaRanch! Please adjust your displayed name to meet the JavaRanch Naming Policy . I am assuming here, but V Bose is very close to Verbose, that is why I believe that this might not be your real name. You can change it here . Thanks! and welcome to the JavaRanch! Mark
Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
subject: ArrayList question