【发布时间】:2020-03-25 01:27:55
【问题描述】:
在 Java 中是否有用于格式化字符串的本机代码或库,如下面用 C# 制作的方式?
来源:Format a string into columns (C#)
public string DropDownDisplay {
get {
return String.Format("{0,-10} - {1,-10}, {2, 10} - {3,5}"),
Name, City, State, ID);
}
}
【问题讨论】:
-
使用
String.format(...)方法。见docs.oracle.com/javase/7/docs/api/java/util/Formatter.html