Replace method doesn't work properly

Posted by John Smith on Stack Overflow See other posts from Stack Overflow or by John Smith
Published on 2013-11-03T15:51:56Z Indexed on 2013/11/03 15:53 UTC
Read the original article Hit count: 221

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about string

Related posts about replace