In core java API I studied the method replace(char oldChar,char newChar)
in String class and it says that it will replace the oldChar
with newChar
in the string in each occurrence, buy this explanation output of this program given below should be
A B D C
But the real output is
A B C C
Can anyone explain me why this is happening so.
class A{
public static void main(String[] args){
String ta = "A ";
ta = ta.concat("B ");
String tb = "C ";
ta = ta.concat(tb);
ta.replace('C','D');
ta = ta.concat(tb);
System.out.println(ta);
}
}