- , , . -
Map<String, String> replaceRules = new HashMap<String, String>();
replaceRules.put("ao", "1");
replaceRules.put("df", "2");
replaceRules.put("n", "3");
String s = replacePartsOf("foobooandfoo", replaceRules);
public String replacePartsOf(String thisString, Map<String, String> withThese) {
for(Entry<String, String> rule : withThese.entrySet()) {
thisString = thisString.replaceAll(rule.getKey(), rule.getValue());
}
return thisString;
}
and after you succeed, reorganize it instead of using arrays of characters. Although I think that what you want to do can be done using StringBuilder, most likely it will not be worth the effort.
source
share