從compareTo
的Javadoc:
如果在這兩個字符串不同的指標,結果是 最低這類指數
在兩個字符的之間的區別
完整的Javadoc:
/**
* Compares this string to the given string.
*
* <p>The strings are compared one {@code char} at a time.
* In the discussion of the return value below, note that {@code char} does not
* mean code point, though this should only be visible for surrogate pairs.
*
* <p>If there is an index at which the two strings differ, the result is
* the difference between the two {@code char}s at the lowest such index.
* If not, but the lengths of the strings differ, the result is the difference
* between the two strings' lengths.
* If the strings are the same length and every {@code char} is the same, the result is 0.
*
* @throws NullPointerException
* if {@code string} is {@code null}.
*/
public native int compareTo(String string);
而且從在線文檔(以上鍊接):
結果是負整數,如果此String對象 字典順序優先於參數字符串
把大量的'?'在你的問題中並沒有幫助你更快得到答案。一個寫得很好的解釋性問題效果最好。我儘可能地爲你整理了它。 –