public static void main(String[] args){
one();
two();
three();
}
public static void one() {
String s1 = "hill5";
String s2 = "hill" + 5;
System.out.println(s1==s2);
}
public static void two() {
String s1 = "hill5";
int i =5;
String s2 = "hill" + i;
System.out.println(s1==s2);
}
public static void three() {
String s1 = "hill5";
String s2 = "hill" + s1.length();
System.out.println(s1==s2);
}
出力は
true
false
false
文字列リテラルはインターンプロセスを使用し、なぜtwo()
とthree()
が false.の場合は理解できますが、three()
明確でtwo()
はありません.しかし、両方の場合について適切な説明が必要です.
誰かが適切な理由を説明してもらえますか?