This question already has an answer here:
- How do I compare strings in Java? 23 answers
Here is my code:
if(editText.getText().toString() == ""){
editTextBenefaction.setText("0");
}
Why he didn't work?
This question already has an answer here:
Here is my code:
if(editText.getText().toString() == ""){
editTextBenefaction.setText("0");
}
Why he didn't work?
Do not use == with Strings use equals()
Change it to
In Java
.equals()
is used to compare if they have the same value and "==" is used to determine if they reference the same object.An even better way is to use
because this will protect against a
NPE
.Java String Docs