按字母顺序对字符串数组排序,按整数数组升序和降序排序

时间:2015-02-05 18:37:55

标签: java arrays

我看过这样的事情:
sorting arrays
而这个 also sorting arrays

但我不知道如何将其与我的代码联系起来。
我有4个阵列;其中三个是按升序和降序排序的数字,但真正令我难过的是第四个数组,它是所有名称,需要按字母顺序排序。
那么我将如何改变这些过去的代码,或者创建一个新的代码来使用这4个数组的调用

        var custName = new Array("Smith, Al","Toms, Andy","Jones, Zack","Vargas, Eddie","Donner, Alice","McMullen, Jessie","Nevins, Carol","Stark, Howard","Neeland, Franny","Boxby, Amos");

        var mnthCharge = new Array(140.00, 42.00, 18.00, 18.00, 36.00, 140.00, 42.00, 24.00, 140.00, 24.00);

        var pastDueAmt = new Array(0, 0, 84.00, 36.00, 0, 18.00, 42.00, 42.00, 96.00, 0);

        var dayPastDue = new Array(0, 0, 60, 60, 0, 30, 90, 30, 120, 0);

或至少第一个按字母顺序排列。

1 个答案:

答案 0 :(得分:0)

你在这里写Scala代码吗?如果是这样,我认为对数组进行排序的正确方法应该是:

var custName = Array("Smith, Al","Toms, Andy","Jones, Zack","Vargas, Eddie","Donner, Alice","McMullen, Jessie","Nevins, Carol","Stark, Howard","Neeland, Franny","Boxby, Amos")
custName = custName.sortWith(_ < _)

Array.sortWith()函数实现了快速排序算法。