Vinod Vijay wrote:What you said was alright and I get that but in your last statement, you said
It returns a new String, with the contents replaced
Does'nt that mean that although a new string object was returned but old characters(\t) were replaced by new characters(<space>) in that?
please explain
You've got it in one. The method does exactly what it says it will do, but what you get back is a
different String.
So, as Stas already pointed out, if you want
name1 to reflect the new value, you must put
name1 = name1.replace("\t", " ");
With the exception of the increment operator, the same is also true of primitives.
If you want to add 46 to an
int, you can't just write
int i;
i + 46;
you have to write
i = i + 46;
Winston