关于Java中的String.format()方法
format
public static String format(Localel, String format, Object... args)
-
使用指定的语言环境、格式字符串和参数返回一个格式化字符串。
-
-
参数:
-
l
- 格式化过程中要应用的 语言环境。如果 l 为 null,则不进行本地化。 -
format
- 格式字符串 -
args
- 格式字符串中由格式说明符引用的参数。如果还有格式说明符以外的参数,则忽略这些额外的参数。参数的数目是可变的,可以为 0。参数的最大数目受 Java Virtual Machine Specification 所定义的 Java 数组最大维度的限制。有关 null 参数的行为依赖于 转换。
返回:
- 一个格式化字符串 抛出:
-
IllegalFormatException
- 如果格式字符串中包含非法语法、与给定参数不兼容的格式说明符,格式字符串给定的参数不够,或存在其他非法条件。有关所有可能的格式化错误的规范,请参阅 formatter 类规范的 详细信息 一节。 -
NullPointerException
- 如果 format 为 null
-
String utput = String.format("It is now %tr on %tD.", currentDateTime, currentDateTime);
String utput = String.format("<input type='text' name='%s' value='%s' >", name, value);