java.text.MessageFormat类的学习
使用比较多的是MessageFormat.format(String pattern, Object … arguments):将pattern中的{}(只能为0-9,需要连续)一替换为argument;
直接上栗子:
String formatStr = MessageFormat.format("helloWorld_{0}_{1}{2}", "000","111","222");
System.out.println(formatStr);
// 输出
helloWorld_000_111222
// 如果{}内的数字非连续则不会替换
String formatStr = MessageFormat.format("helloWorld_{0}_{1}{2}{9}", "000","111","222","999");
System.out.println(formatStr);
// 输出
helloWorld_000_111222{9}