In this example we are checking a sting object containing empty or null value.
Check Empty String
In this example we are checking a sting object containing empty or null value. Apache has provided two methods isBlank() and isNotBlank() for checking the strings..
The class org.apache.commons.lang.StringUtils extends Object class and provides methods that operate on null safe string.
The methods used:
isBlank(String str): This method is used to check whether a string is empty ("") , null or
whitespace.
isNotBlank(String str): This method is used to check whether a string is not empty (""), not null or not a whitespace .
There are two more methods which can be used:
isNotEmpty(String str): Use this method for checking a string
whether it is not empty("") or not null.
isEmpty(String str): Use this method to check a
string for its empty (" ) or null value.
The code of the program is given below:
import org.apache.commons.lang.StringUtils;
|
The output of the program is given below:
C:\rajesh\kodejava>javac CheckEmptyStringExample.java C:\rajesh\kodejava>java CheckEmptyStringExample String one is empty? true String one is not empty? false String two is empty? true String two is not empty?false String three is empty?true String three is not empty?false String four is empty?true String four is not empty?false String five is empty?false String five is not empty?true |