如何将此重构为一行?
String format = "%-20s";
System.out.print(String.format(format, "Property name"));
System.out.println(": property value");
可能我希望有这样的东西,问题是我应该使用format
?
System.out.println(String.format(format, "Property name", ": property value"));
答案 0 :(得分:2)
System.out.printf(format + ": property value%n", "Property name");
但为什么要这么麻烦?
答案 1 :(得分:2)
System.out.printf("%-" + length + "s: %s%n",
"Property name", "property value");