1.代码

        //+
        String arg0 = "Bob";
        String arg1 = "Alice";
        System.out.println("hello," + arg0 + ". I am " + arg1 + ".");

        //StringBuilder.append
        StringBuilder builder = new StringBuilder();
        builder.append("hello,");
        builder.append(arg0);
        builder.append(". I am ");
        builder.append(arg1);
        builder.append(".");
        System.out.println(builder.toString());

        //String.format
        String formatStr = String.format("hello,%s. I am %s.", arg0, arg1);
        System.out.println(formatStr);

        //MessageFormat.format
        String formattedText = MessageFormat.format("hello,{0}. I am {1}.", arg0, arg1);
        System.out.println(formattedText);

 

2.运行结果

hello,Bob. I am Alice.
hello,Bob. I am Alice.
hello,Bob. I am Alice.
hello,Bob. I am Alice.

相关文章:

  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2021-08-24
猜你喜欢
  • 2021-10-02
  • 2022-12-23
  • 2021-06-25
  • 2022-01-29
  • 2021-09-25
  • 2022-01-05
相关资源
相似解决方案