Close

Java Utils - Objects.toString() Examples

Code Snippets Java Utils Java Java API 


Class:

java.util.Objects

java.lang.Objectjava.lang.Objectjava.util.Objectsjava.util.ObjectsLogicBig

Methods:

Null friendly methods, which returns the result of calling toString for a non-null argument and "null" for a null argument.

public static String toString(Object o)
public static String toString(Object o, String nullDefault)

Examples


package com.logicbig.example.objects;

import java.math.BigDecimal;
import java.util.Objects;

public class ToStringExample2 {

public static void main(String... args) {
BigDecimal bd = new BigDecimal("1.3");
String s = Objects.toString(bd);
System.out.println(s);

String x = null;
String s1 = Objects.toString(x, "a default String");
System.out.println(s1);
}
}

Output

1.3
a default String




See Also