java.text.MessageFormat类可以格式化字符串。
public class MessageFormat extends Format
常用方法:
public static String format(String pattern,Object… arguments)这个方法,后面接受可变参数。
其中可以用占位符表示变化部分,占位符的格式为{ ArgumentIndex , FormatType , FormatStyle }。
使用实例:
System.out.println(MessageFormat.format("My name is:{0},age is:{1,number,integer}",new Object[]{"hy",22}));
输出结果:My name is:hy,age is:22