Replace method doesn't work properly
- by John Smith
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?