Java – String

String, StringBuilder, StringBuffer

String is a unchangeable object(although it does not belong to the 8 primitive types). If we change the string, we rebuild a new object that a reference “points” to it. So for an an object that always changes, the speed will slow down (JVM GC). At this time, we use StringBuffer(not thread safe) or StringBuilder(thread safe, available after JDK 5.0) instead.

StringBuilder methods, constructors(click to check official doc)

StringBuilder(int capacity/ String str)

1)append(x)   x could be several types which can be transferred to char

2) insert, reverse, toString, getChar…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s