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