提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
使用Objects.toString将值转换为String
import java.util.Objects; /*来自 n o w j a v a . c o m - 时 代 Java*/ public class Main { public static void main(String[] args) { // toString() method test System.out.println("toString(null) is " + Objects.toString(null)); System.out.println("toString(null, \"XXX\") is " + Objects.toString(null, "XXX")); } }