Home > Back-end >  Had better use the equals equals the judgment string in Java?
Had better use the equals equals the judgment string in Java?

Time:09-16

To determine the empty string "", isn't it also equals. (" ") is better?
Is there a standard approach, can put the null, an empty string (" ", ""," ", etc.), is to "empty string"?

CodePudding user response:

1, if you are using maven, rely on the package org.apache.com mons: Commons - lang3 version is 3.6 (it doesn't matter), maven relied

Org.apache.com mons
Commons - lang3 & lt;/artifactId>
3.6 & lt;/version>

If not using maven download this package directly to the local

2, and then you can directly use the
String STR is empty: no StringUtils. IsNotBlank (STR) :
Determine the string STR is empty: StringUtils. IsBlank (STR) :

CodePudding user response:

Judge empty string use "" equals (XXXX), can avoid a null pointer, as for the way you said, the JDK does not provide, you can write a utility class methods, implementation is simple

CodePudding user response:

Comparing equals the content is same, null and ", "==compare the address values, these two methods is null or" "is not equal
  • Related