What is the difference between StringBuilder and StringBuffer in Java ?
StringBuffer is synchronized i.e. thread safe. It means two threads can't call the methods of StringBuffer simultaneously. It's less efficient as well. StringBuilder is non-synchronized i.e. not thread safe. It means two threads can call the methods of StringBuilder simultaneously. This is highly efficient. I personally prefer using String buffer :-)
Join the Java training in Pune to know more about StringBuffer and StringBuilder. Two significant classes in Java representing mutable String are StringBuffer and StringBuilder that is the string object whose value can be changed. In Java, String is immutable, if there is any modification or operation done on String object for instance: changing it to upper or lower case, adding character, deleting character or in a new String object, substring all the result. Lots of stress can be applied on the Garbage collector because of this if there is a generation of lots of throws away String instances from your application. Initially String Buffer class and later on Stringbuilder were presented by Java developer. Here in this article you will find the difference between Stringbuffer and Stringbuilder: 1) In Java StringBuffer is existing and in StringBuilder was included in Java 5. 2) Both StringBuilder and StringBuffer provides mutable String meaning add/remove character, substring without making new objects. 3) By calling toString () method, the StringBuffer can be converted into String. 4) equals() and hashcode() method is not over-rided by StringBuffer and StringBuilder as they are mutable and not intended to use a hash key based collection classes eg: Hashtable, Hashset, and HashMap. Significance Of Abstract Methods and Classes In Java....SEE MORE==>> http://crbtech.in/Java-Training/difference-stringbuilder-stringbuffer-java/