我正在寻找一些东西来实现以下目标:
String s = "hello {}!";
s = generate(s, new Object[]{ "world" });
assertEquals(s, "hello world!"); // should be true
我可以自己写,但在我看来,我曾经看到过一个库,它可能是 slf4j 记录器,但我不想写日志消息。我只想生成字符串。
你知道有一个图书馆可以做到这一点吗?
See String.format http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#format-java.lang.String-java.lang.Object...- method.
String s = "hello %s!";
s = String.format(s, "world");
assertEquals(s, "hello world!"); // should be true
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)