Скажем, что у меня есть следующий код:
String word1 = "bar";
String word2 = "foo";
String story = "Once upon a time, there was a foo and a bar."
story = story.replace("foo", word1);
story = story.replace("bar", word2);
После выполнения этого кода значение story будет "Once upon a time, there was a foo and a foo."
Аналогичная проблема возникает, если я заменил их в обратном порядке:
String word1 = "bar";
String word2 = "foo";
String story = "Once upon a time, there was a foo and a bar."
story = story.replace("bar", word2);
story = story.replace("foo", word1);
Значение story будет "Once upon a time, there was a bar and a bar."
Моя цель - превратить story в "Once upon a time, there was a bar and a foo." Как я могу это сделать?
