Q:

how to sort array of strings in numerical order?

I have a String[] of prices that might look like this:
String[0] = 1.22
String[1] = 230.08
String[2] = 34.11

I need to cast the array and order it in ascending order. What is the best way to do this? The Array may be very large so performance important. Thank you in advance.

A:

You can define a specialized string comparator:
class MyComparator implements Comparator<String> {
    public int compare(Object a, Object b) {
        return Float.valueOf(a.toString()).compareTo(Float.valueOf(b.toString());
    }
}

and then sort your String array using:
Arrays.sort(aStringArray, new MyComparator());

(N.B. There may be more efficient ways of comparing two strings representing float values.)

