String.format()

    String str = "aaa%sbbb%sccc%s"; // 这种支持很多格式 %s  %d  %f  等
    String format = String.format(str, "111", "222", "333");
    System.out.println(format);
    // 输出 aaa111bbb222ccc333

MessageFormat.format()

    String format1 = MessageFormat.format("aaa{0} bbb {1} ccc {2}", "1111", "2222", "3333");
    System.out.println(format1);
    // 输出 aaa1111 bbb 2222 ccc 3333

StrSubstitutor.replace()

commons.lang3 包 或者commons.lang包中

    Map<String,String> params = new HashMap<>();
    params.put("name","asdf");
    params.put("xxx","jkl");
    String replace = StrSubstitutor.replace("zzz ${name}, xxx ${xxx}", params);
    System.out.println(replace);
    // 输出 zzz asdf, xxx jkl

相关文章:

  • 2023-02-14
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-12
  • 2022-12-23
  • 2021-06-14
  • 2021-10-24
  • 2021-05-28
  • 2022-12-23
相关资源
相似解决方案