hello Preyas,
replace(oldchar, newchar)
--> returns a new string, generated by replacing every occurance of oldchar with newchar. If there is nothing to replace then the returned string is NOT a new string. it returns the same string. No new string is returned.
For Example-1.
if ("sample".replace('s', 'S') == "Sample")
System.out.println("No new Strings returned");
else
System.out.println("New Strings returned");
In Example-1 displays "New Strings returned".
Example-2.
if ("Sample".replace('s', 'S') == "Sample")
System.out.println("No new Strings returned");
else
System.out.println("New Strings returned");
In Example-2 displays "No new Strings returned".
In case of trim() the same rules holds good.
if (" Sample ".trim() == "Sample")
System.out.println("No new Strings");
else
System.out.println("New Strings");
--> displays "New Strings"
if ("Sample".trim() == "Sample")
System.out.println("No new Strings");
else
System.out.println("New Strings");
--> displays "No new Strings"
Hope this helps.
Sunitha. S
[This message has been edited by Sunitha Sounderrajan (edited October 21, 2000).]