0
Date,Lat,Lon,Depth,Mag
20000101,34.6920,-116.3550,12.30,1.21
20000101,34.4420,-116.2280,7.32,1.01
20000101,37.4172,-121.7667,5.88,1.14
20000101,-41.1300,174.7600,27.00,1.90
20000101,37.6392,-119.0482,2.40,1.03
20000101,32.1790,-115.0730,6.00,2.44
20000101,59.7753,-152.2192,86.34,1.48
20000101,34.5230,-116.2410,11.63,1.61
20000101,59.5369,-153.1360,100.15,1.62
20000101,44.7357,-110.7932,4.96,2.20
20000101,34.6320,-116.2950,9.00,1.73

I need to sort these data by each criterion

I tried Double.parseDouble(array[0].split(",").[1]) but takes too much time using Selection Sort

Is there any way to just sort by not using parseDouble?

August
  • 12,410
  • 3
  • 35
  • 51

2 Answers2

2

You have strings that you want to sort by a certain substring interpreted as a Double, so no way around parsing them. But if you parse each line once, and save those results to sort on, that will be faster than calling parseDouble within each comparison.

Scott Hunter
  • 48,888
  • 12
  • 60
  • 101
1

I suppose you could create a class that represents the data on each line. Parse the data into instances of that class and then sort on the objects.

Zymus
  • 1,673
  • 1
  • 18
  • 38