1 回答
TA贡献1946条经验 获得超3个赞
规则 a.compareTo(b)
returns negative value
:a is before b
returns 0
:a equal to b
return positive value
:a is after b
因为参数是,first, second
并且您进行比较,second.compareTo(first)
您将获得相反的顺序:
second+first) 344 first+ second 434 comparing : -1 >> 4 is before 34
(second+first) 423 first+ second 234 comparing : 2 >> 23 is after 4
(second+first) 3423 first+ second 2334 comparing : 1 >> 23 is after 34
(second+first) 3415 first+ second 1534 comparing : 2 >> 15 is after 34
(second+first) 2315 first+ second 1523 comparing : 1 >> 15 is after 23
使用这5before/after条规则,顺序是4 34 23 15
这是Reverse Lexical Order(词汇,因为使用String,反向,因为与第一比较第二)
一种情况的详细信息
该
sort
方法将比较4
和34
,因此first=4
和second=34
您进行计算
"344".compareTo("434")
,因为344在434之前是344的词汇顺序由于
-1
该sort
方法会记得4
是前34
添加回答
举报