Hi Hades,
Nain is right in saying that s.replace('i','e') has no effect on 's' and is returning a reference to the original string. This is happening because
(1) there is no 'i' in 'Hello'. The definition for String replace is <code>
String replace( oldChar, newChar )</code>.
(2) you are not storing the new string reference anywhere
Try the following
<code>
class Happy3 {
static String s ="Hello";
public static void main(String args[]) {
Happy3 h = new Happy3();
System.out.println(methodA(s));
System.out.println( s );
}
public static String methodA(String s) {
String str = s.replace('e','i');
str += " World !!!" ;
return str;
}
}
Output:
Hillo World !!!
Hello
</code>
A new String is created in methodA(), the original String 's' is not changed.
Hope that helps.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
Co-author
Mike Meyers' Java 2 Certification Passport