Check for an empty string : String « Data Type « Java






Check for an empty string

    
 
import org.apache.commons.lang.StringUtils;

public class Main {
  public static void main(String[] args) {
    String var1 = null;
    String var2 = "";
    String var3 = "    \t\t\t";
    String var4 = "Hello World";

    System.out.println("var1 is blank? = " + StringUtils.isBlank(var1));
    System.out.println("var2 is blank? = " + StringUtils.isBlank(var2));
    System.out.println("var3 is blank? = " + StringUtils.isBlank(var3));
    System.out.println("var4 is blank? = " + StringUtils.isBlank(var4));

    System.out.println("var1 is not blank? = " + StringUtils.isNotBlank(var1));
    System.out.println("var2 is not blank? = " + StringUtils.isNotBlank(var2));
    System.out.println("var3 is not blank? = " + StringUtils.isNotBlank(var3));
    System.out.println("var4 is not blank? = " + StringUtils.isNotBlank(var4));

    System.out.println("var1 is empty? = " + StringUtils.isEmpty(var1));
    System.out.println("var2 is empty? = " + StringUtils.isEmpty(var2));
    System.out.println("var3 is empty? = " + StringUtils.isEmpty(var3));
    System.out.println("var4 is empty? = " + StringUtils.isEmpty(var4));

    System.out.println("var1 is not empty? = " + StringUtils.isNotEmpty(var1));
    System.out.println("var2 is not empty? = " + StringUtils.isNotEmpty(var2));
    System.out.println("var3 is not empty? = " + StringUtils.isNotEmpty(var3));
    System.out.println("var4 is not empty? = " + StringUtils.isNotEmpty(var4));
  }
}

   
    
    
    
  








Related examples in the same category

1.Get String hash code
2.To extract Ascii codes from a String
3.LengthOf - show length of things
4.Show string escapesShow string escapes
5.Convert string to char array
6.See if Strings are shared in Java
7.Find text between two strings
8.If a string is empty or not
9.Count word occurrences in a string
10.Remove leading and trailing space from String
11.Reverse a string
12.Put quotes around the given String if necessary.
13.Starts With Ignore Case
14.Repeat String
15.implements CharSequence