java API
public static String format(String format,
Object... args)
-
使用指定的格式字符串和参数返回一个格式化字符串。
始终使用
Locale.getDefault()
返回的语言环境。 -
-
- 参数:
-
format
- 格式字符串 -
args
- 格式字符串中由格式说明符引用的参数。如果还有格式说明符以外的参数, - 则忽略这些额外的参数。参数的数目是可变的,可以为 0。
- 参数的最大数目受 Java Virtual Machine Specification 所定义的 Java 数组最大维度的限制。有关 null 参数的行为依赖于转换。
- 返回:
- 一个格式化字符串
- 抛出:
-
IllegalFormatException
- 如果格式字符串中包含非法语法、与给定的参数不兼容的格式说明符, - 格式字符串给定的参数不够,或者存在其他非法条件。有关所有可能的格式化错误的规范,
- 请参阅 formatter 类规范的详细信息 一节。
-
NullPointerException
- 如果 format 为 null
1 String s = String.format("\t\t%s\n\t\t%-20s%-20s\n", 2 "消息 : "+msg, 3 "TTL = "+TTL, 4 "序号 : "+ICMP_index);