java 占位符

    @Test
    void contextLoads() {
        String s1 = "你好{0}, 我叫{1}";
        System.out.println(MessageFormat.format(s1, "张飞", "王菲"));

        String s2 = "你好%s, 我叫%s";
        System.out.println(String.format(s2, "张1飞", "王1菲"));
    }

字符串可以直接拼接,也可以使用占位符

推荐使用占位符

 

posted @ 2020-07-22 22:27  市丸银  阅读(143)  评论(0编辑  收藏  举报