【发布时间】:2018-03-03 20:01:38
【问题描述】:
我正在使用一个代码,我想用另一个字符串填充几个字符串占位符。这是我用来测试代码的示例文本。
String myStr = "Media file %s of size %s has been approved"
这就是我填充占位符的方式。因为我希望使用几个占位符,所以我使用了 java Map.
Map<String, String> propMap = new HashMap<String,String>();
propMap.put("file name","20mb");
String newNotification = createNotification(propMap);
我使用以下方法创建字符串。
public String createNotification(Map<String, String> properties){
String message = "";
message = String.format(myStr, properties);
return message;
}
如何将“%s”中的两个替换为“文件名”和“20mb”?
【问题讨论】:
标签: java string hashmap mapping placeholder