怎么使用map中的key,替换字符串中{}中的占位符? 代码如下,请大神赐教……
String str = "我是{name},我来自{city},今年{age}岁";
Map<String, String> mapstring = new HashMap<String, String>();
mapstring.put("name", "小明");
mapstring.put("age", "15");
mapstring.put("city", "北京");
……………………
System.out.println("我是小明,我来自北京,今年15岁");
Not sure why there is such a requirement, but the following code should meet the requirement:
Just finished writing the answer, the correct answer is upstairs
String a = "I am {name}, I come from {city}, I am {age} years old this year";
Haha I will give you a tool class that I packaged
/**
String formatting
@author Du
*/
public class DFormat {
}