java sort()怎么实现的_Java中Array.sort()的排序原理

People[]people={newPeople("小飞飞","2","2:41:28"),newPeople("小国","2","11:1:32"),newPeople("小威","4","17:23:3"),newPeople("大飞","2","14:52:13"),newPeople("晶晶","1","2...

People[] people={

new People("小飞飞","2","2:41:28"),

new People("小国","2","11:1:32"),

new People("小威","4","17:23:3"),

new People("大飞","2","14:52:13"),

new People("晶晶","1","2:18:25"),

new People("死佳","2","4:13:15"),

new People("旭旭","2","4:48:39"),

new People("阿雪","1","3:34:13"),

new People("小强","1","2:53:47") };

Arrays.sort(people);

为什么它会用第二个字符串排序呢,sort的底层排序是什么原理啊!求各位大虾指点!在线等。。。。。。。

我的People类

class People implements Comparable{

String name;

String times;

String time;

public People(String name,String times,String time){

this.name=name;

this.times=times;

this.time=time;

}

public int compareTo(People p1){

int countc=times.compareTo(p1.times);

int countt=p1.time.compareTo(p1.time);

return countc!=0?countc:countt;

}

public String toString(){

return name+" "+times+" "+time;

}

}

一楼说的优先级问题,但我的都是字符串啊,问什么它他按第一个字符串的字典顺序排呢,第二个字符串难道会在Java内部自动转换成字符串,然后在按优先级排序吗,还是不太懂,大虾在指点一下

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值