Java compareToIgnoreCase() 方法
Java 教程
· 2019-02-08 19:42:11
compareToIgnoreCase() 方法用于按字典顺序比较两个字符串,不考虑大小写。
语法
int compareToIgnoreCase(String str)
参数
str -- 要比较的字符串。
返回值
- 如果参数字符串等于此字符串,则返回值 0;
- 如果此字符串小于字符串参数,则返回一个小于 0 的值;
- 如果此字符串大于字符串参数,则返回一个大于 0 的值。
实例
public class Test {
public static void main(String args[]) {
String str1 = "STRINGS";
String str2 = "Strings";
String str3 = "Strings123";
int result = str1.compareToIgnoreCase( str2 );
System.out.println(result);
result = str2.compareToIgnoreCase( str3 );
System.out.println(result);
result = str3.compareToIgnoreCase( str1 );
System.out.println(result);
}
}
以上程序执行结果为:
0 -3 3
点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html
Database Design and Implementation
Edward Sciore / Wiley / 2008-10-24 / 1261.00 元
* Covering the traditional database system concepts from a systems perspective, this book addresses the functionality that database systems provide as well as what algorithms and design decisions will......一起来看看 《Database Design and Implementation》 这本书的介绍吧!