Java{0}占位符替换字符串

Java{0}占位符替换字符串

public class Test {
    public static void main(String[] args) {
        System.out.println(String.format("http://www.{0}.com", "baidu"));//错误的
        System.out.println(String.format("http://www.%s.com", "baidu"));//%s替换字符串
        System.out.println(String.format("http://www.%S.com", "baidu"));//%S替换字符串(大写)
        System.out.println(MessageFormat.format("http://www.{0}.com", "baidu"));
    }
}

【验证结果】:

原文地址:https://www.cnblogs.com/baijinqiang/p/12059726.html