Java 中使用 == 运算符比较字符串
您可以使用 == 运算符比较两个字符串。但它比较的是给定变量的引用,而不是值。
实例
public class Sample {
public static void main(String args[]){
String str1 = "hello";
String str2 = "hello";
System.out.println(str1 == str2);
}
}输出
true
广告
您可以使用 == 运算符比较两个字符串。但它比较的是给定变量的引用,而不是值。
public class Sample {
public static void main(String args[]){
String str1 = "hello";
String str2 = "hello";
System.out.println(str1 == str2);
}
}true