1.java中格式化字符串常用的方式有MessageFormat.format和String.format
示例如下:
如下:
String format1 = MessageFormat.format("我是{0},我{1}", "中国人", 18);
System.out.println(format1);
Object[] testArgs = {new String("张三"),new String("大傻子")};
Object testArgs1 = testArgs;
MessageFormat form = new MessageFormat("{0}是个{1}");
String format = form.format(testArgs1);
System.out.println(format);
String format2 = String.format("我是%s,我%d", "中国人", 18);
System.out.println(format2);
输出结果如下:
我是中国人,我18
张三是个大傻子
我是中国人,我18
这两者的性能如何呢?
答案是MessageFormat.format优于String.format
详细请参考:https://www.cnblogs.com/huhx/p/baseusejavamessageformat.html