Difference b/w string and string buffer in tabular form String StringBuffer/StringBuilder 1 String Object is immutable. StringBuffer/StringBuilder Object is mute 2 Immutable means the value stored in the String object can’t be changed. Mutable means the value stored in the String object can be changed. 3 Inefficient Efficient. 4 ‘overloaded mathematical operators’ (‘+’) is used for adding strings which generates string new instances everytime. Example: String st = “Hello”; st = st + “Java”; ‘append’ is used for adding two or more strings which expands StringBuffer. Example: StringBuilder sb = new StringBuilder(“Hello”); sb.append(“Java”); 5 String is not synchronized. Which means it is not thread safe. StringBuilder/StringBuffer is synchronized. Which is thread safe and hence you can use it when you implement threads for methods. 6 Po...
FOR EVERY PROGRAMMER SOME SPECIAL PROGRAMS WITH THEORY.