Java generating Strings with placeholders

前端 未结 8 829
北恋
北恋 2020-12-15 14:46

I\'m looking for something to achieve the following:

String s = \"hello {}!\";
s = generate(s, new Object[]{ \"world\" });
assertEquals(s, \"hello world!\");         


        
8条回答
  •  鱼传尺愫
    2020-12-15 15:41

    You won't need a library; if you are using a recent version of Java, have a look at String.format:

    String.format("Hello %s!", "world");
    

提交回复
热议问题