从jdk1.5开始,java.lang.String新增了2个format方法,签名分别是:
static String | format(Locale l, String format, Object... args)
Returns a formatted string using the specified locale, format string, and arguments.
|
static String | format(String format, Object... args)
Returns a formatted string using the specified format string and arguments.
|
这2个方法提供了类似crt中printf函数的能力,使用方法也是类似的,基本的格式化字符也基本保持一致,完整的格式见format string。