buwei
第一种:使用%s占位,使用String.format转换
 
public class Test {
public static void main(String[] args) {
String url = "我叫%s,今年%s岁。";
String name = "小明";
String age = "28";
url = String.format(url,name,age);
System.out.println(url);
}
}
 
控制台输出:
我叫小明,年28岁。
 
第二种:使用{1}占位,使用MessageFormat.format转换
public class Test {
public static void main(String[] args) {
String url02 = "我叫{0},今年{1}岁。";
String name = "小明";
String age = "28";
url02 = MessageFormat.format(url02,name,age);
System.out.println(url02);
}
}
控制台同样输出:
我叫小明,今年28岁。

分类:

技术点:

相关文章:

  • 2021-12-01
  • 2021-10-03
  • 2021-07-25
  • 2021-06-11
  • 2021-10-18
  • 2021-11-28
  • 2021-12-22
  • 2022-01-02
猜你喜欢
  • 2021-12-26
  • 2021-12-11
  • 2021-11-09
  • 2021-10-18
  • 2021-10-10
  • 2021-11-27
  • 2021-11-22
相关资源
相似解决方案