Java study notes-MessageFormat.format usage

1.MessageFormat.format

It is inserted according to the order and placeholders. The placeholders are {1}, {2}, etc. This form is used as a placeholder, and the placeholder is followed by the corresponding value

 

2. Usage

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()));
    }

}

 

Guess you like

Origin blog.csdn.net/mumuwang1234/article/details/115351188