compareTo()实际返回什么? [英] What does compareTo() actually return?
本文介绍了compareTo()实际返回什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Java中的 compareTo()
方法返回的值大于/等于/小于0,我知道.但是,价值本身就是我的问题.返回 compareTo()
时2或4有什么区别.看下面的代码
The compareTo()
method in Java returns a value greater/equal/less than 0 and i know that. However, the value itself is my question. What is the difference between 2 or 4 when compareTo()
returns. Look at the code below
String s1="hello";
String s2="hello";
String s3="meklo";
String s4="hemlo";
System.out.println(s1.compareTo(s2)); // 0
System.out.println(s1.compareTo(s3)); // -5
System.out.println(s1.compareTo(s4)); // -1
为什么最后两个命令是-5和-1?
Why the last two commands are -5 and -1?
推荐答案
查看全文