我想动态地用列表值替换字符串,而无需硬编码.
就像“ list.get(0)”
在第一次迭代中,==> str = str.replace(“ {Name}”,’一个’);
在第二迭代中,==> str = str.replace(“ {subInterfaceId}”,’Two’);
提前致谢.
String str = "Iamstillquite/{Name}/newtoJava/programm/ingandIam/{subInterfaceId}/tryingtoupdate/anexisting";
List<String> list = new ArrayList<>();
list.add("One");
list.add("Two");
for (String s : list) {
str = str.replace("{Name}",s);
}
@H_404_14@
预期产量:
String finalstr = "Iamstillquite/One/newtoJava/programm/ingandIam/Two/tryingtoupdate/anexisting";
@H_404_14@
最佳答案