Monday, April 30, 2007

What is the difference between String and StringBuffer?

String objects are immutable. It means any method like concat, substring, replace called upon an existing String object will return a new String object i.e. updations of an existing String object will not be reflected in the same object rather a new String object will be created.

A StringBuffer implements a mutable sequence of characters, which can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. The principal operations on a StringBuffer are the append and insert methods, which are overloaded so as to accept data of any type. Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string buffer. The append method always adds these characters at the end of the buffer; the insert method adds the characters at a specified point.


Anonymous said...

Good Answer


Interview Questions On Java,Java EE Copyright © 2016. Reads: best tracker