How can i campare a textfield.settext with a string for example:
if(textField_1.setText != ("Hello"))
I can't do !=, how can i do it?
if(!textField_1.setText.equals("Hello"))
That's Java :)
you can use != and == to compare references and basic types (int, float ... )
In c++ we can overload the operator, but in java we have to use equals()
This is how the string comparision should be done.
if(textField_1.setText.equals("Hello")){
}
Update:
I think you must use the get method to get the text, therefore I am expecting textField_1.getText()
will give you the text to be compared.
Refer this
You need to use getText()
method to compare.
if(textField_1.getText() != ("Hello")){
//not matched
}else{
//matched
}
But it is better to use equals() method to compare.
if(!textField_1.getText().equals("Hello")){
//not matched
}else{
//matched
}
Note That:
==
tests for reference equality.
.equals(
) tests for value equality.