MessageFormat.format() String字符串设置占位符,动态替换

 方式1:MessageFormat.format()

String format = MessageFormat.format("aaa{0}bbbb{1}ccc", "张", "凡");
System.out.println(format);//aaa张bbbb凡ccc

参考:https://www.cnblogs.com/pc-boke/articles/9121782.html

 

方式二:String.format()

String s = String.format("aaa%sbbbb%sccc", "张", "凡");
System.out.println(s);

参考:https://blog.csdn.net/anita9999/article/details/82346552

 

方式三:StrUtil.format()

String format = StrUtil.format(LivePkRedisKey.LIVE_PK_ROOM_SUMMARY.getKey(),"张");
System.out.println(format);

 

你可能感兴趣的:(java-基础)