how to check if a string is empty or null in Android Studio
24,888
Just Use
if(TextUtils.isEmpty(/* your String*/)){
// String is empty or null
}else {
// string has value
}
Author by
John Champion
Updated on July 09, 2022Comments
-
John Champion almost 2 years
In my project I have an
edit text
field and its name iseditText
also I have assignmTextEmri = (EditText) findViewById(R.id.editText);
I want to get its value and I have done it with the following statmentString emridhene = mTextEmri.getText().toString();
Now I want to check it if it is
null
orempty
I have tried this code but it is not workingif (emridhene.toString() == null || emridhene.toString() == "") { mTextViewKonfirm.setText("Ju lutem shkruani nje Emer"); } else{ mTextViewKonfirm.setText(emridhene); }
How can I make it to work. Thanks.