Hello I have a string and when I try to use replace method in for loop it doesn't work
String phrase="hello friend";
String[] wordds=phrase.split(" ");
String newPhrase="sup friendhello weirdo";
for (int g=0;g<2;g++)
{
finalPhrase+=newPhrase.replace(wordds[g],"");
}
System.out.println(finalPhrase);
It prints out sup hello weirdo
and I expect it to print sup weirdo
.
What am I doing wrong?