我有一个字符串"sss"
和一个字符数组{'s','s','s'}
。我将数组转换为字符串,但在比较它们时不会打印“两者相等”的消息。为什么?
public class RoughActivity extends Activity
{
private Button checkButton;
private TextView text;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
start();
}
private void start() {
int i;
checkButton=(Button)findViewById(R.id.go);
text=(TextView)findViewById(R.id.display);
final String question="sss";
final char answer[]=new char[question.length()];
for(i=0;i<question.length();i++)
{
answer[i]='s';
}
checkButton.setOnClickListener(new View.OnClickListener(){ //on clicking the button,the text must be filled with "both are equal"
public void onClick(View v){
if(question.equals(answer))
{
text.setText("both are equal");
}
}});
}
}