Java学习笔记-MessageFormat.format用法

1.MessageFormat.format

是根据顺序和占位符来对应插入的,占位符是{1},{2},等这种形式作为占位符,占位符后面是顺序对应的值

2.用法

public class Test {

    public static void main(String[] args){

        String a= "aaa";

        String b= "bb";

        String c= "c";

        StringBuilder sb = new StringBuilder();

        sb.append(a).append(b).append(c);

        System.out.println(MessageFormat.format("这些是占位符,第一个是:{0},第二个是:{1} ,第三个是:{2},第四个是:{3}", a, b,"",sb));

        System.out.println(MessageFormat.format("这些也是占位符,第一个是:''{0}'',第二个是:'{1}',第3个是:{2},第四个是:{3}", a, b,"",sb.toString()));
    }

}

猜你喜欢

转载自blog.csdn.net/mumuwang1234/article/details/115351188