Hi, 
I have got a doubt In String. String objects are Immutable and StringBulider/StringBuffer objects are mutable. Almost we can do all the String functionality in StringBulider. Then why we need to use String instead of String builder/StringBuffer. Is there any specific reason available for using String? kindly clarify my doubt.    

Recommended Answers

All 3 Replies

Strings are supported as a special case in the compiler and are very highly optimised. The fact that they are immutable allows all kinds of optimisations that are not possible for mutable objects, especially in a multi-threaded environment.

I agree, but if you work with String (concating 1000 times) it is better to use StringBuilder because he is faster then String. Code example on this link:

There's a place for both, it's no popularity contest of "which is best" without any classification as to what scenario is being considered.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.