What does Java – compareto() actually return?

The CompareTo () method in Java returns a value greater than / equal to / less than 0 But value itself is my problem When compareto() returns, what is the difference between 2 or 4 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

Why are the last two commands - 5 and - 1?

Solution

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#compareTo (java.lang.String)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>