Java中的大小写敏感字符串比较。
可以使用equals()方法或compareTo()方法比较两个字符串。
其中,
- equals()方法将此字符串与指定对象进行比较。
- compareTo()方法按字典顺序比较两个字符串。比较基于字符串中每个字符的Unicode值。
这两种方法比较给定字符串时,都考虑了大小写,即大小写不同的字符串将被视为不同的字符串。
示例
以下示例演示了使用equals()方法比较两个字符串。
public class Sample{
public static void main(String args[]) {
String str = "Hello World";
String anotherString = "hello world";
Object objStr = str;
System.out.println( str.equals(anotherString) );
}
}输出
false
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C编程
C++
C#
MongoDB
MySQL
Javascript
PHP