String : immutable..it means value stored in the object is can not be changed.
When we make any changes on that String internally it will create the new String.
String myStyle = "style1"; myStyle= myStyle+"style2";
In the above example it will craete the two strings.
StringBuffer : mutable..it means value Stored in the object is can be changed.
StringBuffer is Synchronized ..Which means it is thread safe .only one thread access at a time.
StringBuilder : mutable..it means value Stored in the object is can be changed.
StringBuilder is more efficient than StringBuffer.Because it is not synchronized.more than one thread access at a time.
When we make any changes on that String internally it will create the new String.
String myStyle = "style1"; myStyle= myStyle+"style2";
In the above example it will craete the two strings.
StringBuffer : mutable..it means value Stored in the object is can be changed.
StringBuffer is Synchronized ..Which means it is thread safe .only one thread access at a time.
StringBuilder : mutable..it means value Stored in the object is can be changed.
StringBuilder is more efficient than StringBuffer.Because it is not synchronized.more than one thread access at a time.
0 Response to "Difference between String,StringBuffer and StringBuilder"
Post a Comment