Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML

Search:
   Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML Facing Programming Problem? Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
Check Empty String
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;
 
public class CheckEmptyStringExample 
{    
    public static void main(String[] args)
    {
    String string1 = "";
    String string2 = "\t\r\n";
    String string3 = "     ";
    String string4 = null;
    String string5 = "Hi"
    System.out.println("\nString one is empty? " 
StringUtils.isBlank
(string1));
    System.out.println("String one is not empty? " +
 StringUtils.isNotBlank
(string1));
    System.out.println("\nString two is empty? " 
StringUtils.isBlank
(string2));
    System.out.println("String two is not empty?" 
StringUtils.isNotBlank
(string2));
    System.out.println("\nString three is empty?" 
StringUtils.isBlank
(string3));
    System.out.println("String three is not empty?" +
StringUtils.isNotBlank
(string3));
    System.out.println("\nString four is empty?" 
StringUtils.isBlank
(string4));
    System.out.println("String four is not empty?" 
StringUtils.isNotBlank
(string4));
    System.out.println("\nString five is empty?" 
StringUtils.isBlank
(string5));
    System.out.println("String five is not empty?" 
StringUtils.isNotBlank
(string5))
    }
}
 

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

Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:


reallt this sire helped more to explore me.

sanjay

Posted by sanjay on Wednesday, 04.30.08 @ 21:57pm | #58239

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.