0 votes
1 view
in Java by (10.2k points)

I'm parsing HTML data. The String may be null or empty when the word to parse does not match.

So, I wrote it like this:

if(string.equals(null) || string.equals("")){

    Log.d("iftrue", "seem to be true");

}else{

    Log.d("iffalse", "seem to be false");

}

When I delete String.equals(""), it does not work correctly.

I thought String.equals("") wasn't correct.

How can I best check for an empty String?

1 Answer

0 votes
by (46.1k points)

right method to check for null or empty is like this:

if(str != null && !str.isEmpty()) { /* do your stuffs here */ }

Related questions

0 votes
1 answer
0 votes
2 answers
asked Jul 9, 2019 in Java by Anvi (10.2k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...