我如何使用compareToIgnoreCase方法?

bab*_*eps -6 java string methods

我如何使用compareToIgnoreCase字符串类的方法来查看字符串是否小于或更大,然后是另一个字符串?看到我不能用" >"和" <".

Pau*_*mer 5

此例程返回-1,0或1作为值,因此您可以执行以下操作:

String first;
String second;
... assign first and second

if( first.compareToIgnoreCase(second) < 0) {
    // second is less than first...
} else if first.compareToIgnoreCase(second) == 0) {
    // second is same as first...
} else if first.compareToIgnoreCase(second) > 0) {
    // second is greater than first...
}
Run Code Online (Sandbox Code Playgroud)