tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Commons Lang3 > Arrays > Null to Empty

Null to Empty 

Apache Commons Lang 3.0 is a java library with lot of utilities and reusable components. This requires the library commons-lang3-3.0.1.jar to be in classpath. The following example shows using ArrayUtils.nullToEmpty() API. It converts the null reference to empty reference.

File Name  :  
com/bethecoder/tutorials/commons_lang/tests/arrays/NullToEmptyTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.commons_lang.tests.arrays;

import org.apache.commons.lang3.ArrayUtils;

public class NullToEmptyTest {

  /**
   @param args
   */
  public static void main(String[] args) {

    String [] strings = null;
    int [] ints = null;

    strings = ArrayUtils.nullToEmpty(strings);
    ints = ArrayUtils.nullToEmpty(ints);
    
    System.out.println("String array length : " + strings.length);
    System.out.println("Integer array length : " + ints.length);
  }

}
   

It gives the following output,
String array length : 0
Integer array length : 0


                    Print

   



Books Recommendation

 
 
bl  br