c# – Java等效于.NET的String.Format

在Java中有相当于.NET的String.Format吗?
最佳答案
看看String.formatPrintStream.format的方法。

两者都是基于java.util.Formatter class

String.format示例:

Calendar c = new GregorianCalendar(1995, MAY, 23);
String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);
// -> s == "Duke's Birthday: May 23, 1995"

System.out.format示例:

// Writes a formatted string to System.out.
System.out.format("Local time: %tT", Calendar.getInstance());
// -> "Local time: 13:34:18"

转载注明原文:c# – Java等效于.NET的String.Format - 代码日志