Explain what?
* The definition of "immutable"?
* The design decision that String ought to be immutable?
* How String's API demonstrates string is immutable?
Hi,
I have some explanation to answer your query..
i) Definition of "immutable": "immutable" means "unchange" or "not able to change".
ii)String ought to be immutable:
please try out the following example..it explains good...
- class String_immutable{
-
public sttaic void main(String args[]){
-
String s1 = new String("StringValue");
-
StringBuffer s2 = new StringBuffer("String buffer value");
-
s1.replace('a','b');
-
s2.replace(0,2,"zzz");
-
System.out.println("\n String value after replace "+s1+" String buffer
-
after replace "+s2);
-
}
-
}
From above v clearly understand that "String" values are immutable and where as "String buffer" values are mutable.
iii) Api's:
you may try out with any API's . for better understanding "replace()" can be used..
-Thanks & Regards,
Hamsa