Java – Check Empty String with Apache Commons

Apache Commons IO provides the StringUtils Class for checking empty string in Java.

Add the Apache Commons Lang in the pom.xml.

...
<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-lang3</artifactId>
  <version>3.0.1</version>
</dependency>
...

 

Try the following Class.

import org.apache.commons.lang3.StringUtils;

public class CheckEmptyString {
  public static void main(String[] args) {
    String testString = null;
		
    if (StringUtils.isEmpty(testString)) {
      System.out.println("This string is empty.");
    }
  }
}

 

Done =)

About these ads

5 thoughts on “Java – Check Empty String with Apache Commons”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s