1.MessageFormat.format
import java.text.MessageFormat; /** * Created by SYJ on 2017/9/13. */ public class MainTest { public static void main(String[] args) { String url = "http://xxx.xxx.xxx?name={0}&age={1}"; String path = MessageFormat.format(url, "张三", 18); System.out.println(path);//http://xxx.xxx.xxx?name=张三&age=18 } }
2.String.format
/** * Created by SYJ on 2017/9/13. */ public class MainTest { public static void main(String[] args) { String url = "http://xxx.xxx.xxx?name=%s&age=%d"; String path = String.format(url, "张三", 18); System.out.println(path);//http://xxx.xxx.xxx?name=张三&age=18 } }