tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Google Guava > Basic > String Null to Empty

String Null to Empty 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Strings.nullToEmpty() API. It returns EMPTY string if the given string is NULL otherwise returns the original string.

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.guava.base_tests;


public class NulltoEmptyTest {

   @param args
  public static void main(String[] args) {
    String str = null;
    str = Strings.nullToEmpty(str);
    System.out.println("String length : " + str.length());

It gives the following output,
String length : 0



Books Recommendation

Your Ad Here
bl  br