在Java中比较字符串及字符串部分
下面是使用Java比较字符串及字符串部分的示例?请通过示例进行说明。
示例
public class StringDemo {
public static void main(String[] args) {
String str1 = "tutorials point";
String str2 = str1.substring(10);
int result = str1.compareTo(str2);
// prints the return value of the comparison
if (result < 0) {
System.out.println("str1 is greater than str2");
} else if (result == 0) {
System.out.println("str1 is equal to str2");
} else {
System.out.println("str1 is less than str2");
}
}
}输出
str1 is less than str2
Advertisement
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP