ObjectUtils.defaultIfNull : ObjectUtils « Apache Common « Java Tutorial






import org.apache.commons.lang.ObjectUtils;

public class MainClass {
    public static void main(String[] args) {
        //Create ObjectUtilsTrial instance
        MyClass one = new MyClass();
        MyClass two = one; //Same Reference
        MyClass three = new MyClass(); //New Object
        MyClass four = null;

        //four is null, returns DEFAULT
        System.out.print("1) If null return DEFAULT >>>");
        System.out.println(ObjectUtils.defaultIfNull(four, "DEFAULT"));

    }

}

class MyClass{
    public String toString() {
        return "toString Output";
    }

}
1) If null return DEFAULT >>>DEFAULT
  Download:  CommonLangObjectUtils.defaultIfNull.zip( 199 k)








37.10.ObjectUtils
37.10.1.ObjectUtils.toString
37.10.2.ObjectUtils.identityToString
37.10.3.ObjectUtils.equals2
37.10.4.ObjectUtils.equals
37.10.5.ObjectUtils.defaultIfNull