Boolean to String
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 converting boolean to string.
package com.bethecoder.tutorials.commons_lang.tests.booleans;
import org.apache.commons.lang3.BooleanUtils;
public class BooleanToStringTest {
/**
* @param args
*/
public static void main ( String [] args ) {
System.out.println ( BooleanUtils.toStringOnOff ( null )) ;
System.out.println ( BooleanUtils.toStringOnOff ( Boolean.TRUE )) ;
System.out.println ( BooleanUtils.toStringOnOff ( Boolean.FALSE )) ;
System.out.println ( BooleanUtils.toStringTrueFalse ( null )) ;
System.out.println ( BooleanUtils.toStringTrueFalse ( Boolean.TRUE )) ;
System.out.println ( BooleanUtils.toStringTrueFalse ( Boolean.FALSE )) ;
System.out.println ( BooleanUtils.toStringYesNo ( null )) ;
System.out.println ( BooleanUtils.toStringYesNo ( Boolean.TRUE )) ;
System.out.println ( BooleanUtils.toStringYesNo ( Boolean.FALSE )) ;
}
}
It gives the following output,
null
on
off
null
true
false
null
yes
no