가능한 중복 :
Java String.equals versus ==문자열 겉으로는 동일하지 사용하여 문자열()
내가 너무 일을 쉽게 기대하지 않습니다 자바에 새로운 오전하지만 나를 완전히 충격 쉘이 . 지구에 이유는하지 않습니다 문이 제대로 평가되는 경우 :
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class StringMystery extends JFrame {
JTextArea txt = new JTextArea();
String string1 = "abcde";
String string2 = string1.substring(0,4);
public StringMystery() {
setLayout(null);
txt.setBounds(20, 20, 100, 100);
add(txt);
txt.setText(string2);
//string 2 is definitely equal to "abcd" but this doesn't evaluate:
if (string2 == "abcd"){
txt.setText("string2 = abcd");
}
}
public static void main(String[] args) {
StringMystery jtxt = new StringMystery();
jtxt.setSize(200,200);
jtxt.setTitle("String Mystery");
jtxt.setVisible(true);
}
}
다른 백만 개의 문자열 == 질문 – Qwerky