이 프로그램에서 내가 실수 한 부분을 말해 줄 수 있습니까 .조건이 일치하면 두 개의 동일한 문자열이 일치하지 않는 이유는 무엇입니까?
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<Applet code="kk" height=400 width=400></applet>*/
public class kk extends Applet implements ActionListener
{
Button b;
TextField t;
String str1,str2;
public void init()
{
b=new Button("submit");
t=new TextField(20);
add(t);
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
try
{
str2="mohit";
str1=t.getText();
if(str1==str2)
{
System.out.println("matched");
}
else
{
System.out.println("not matched");
}
}
catch(Exception e)
{
System.out.println("Exception caught ");
}
}
}
왜 str1과 str2가 일치하지 않는지 모릅니다.
[Java의 문자열을 어떻게 비교합니까?] (http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Makoto