JAVA | Compare between string and string buffer class.

String 
1. String is a major class 
2. The length of the String object is fixed. 
3. String object is immutable.
4. It is slower during concatenation. 
5. String object cannot be modified. 
6. String object can be created without calling a constructor of String class.
Eg: String str=”abc”; 

String buffer class 
1. StringBuffer is a peer class of String
2. The length of the StringBuffer object is flexible.(can be changed)
3. StringBuffer object is mutable. 
4. It is faster during concatenation.
5. StringBuffer object contents can be modified.
6. StringBuffer object needs constructor to initialize created object.
Eg: StringBuffer str=new StringBuffer(“abc”); 



Post a Comment

0 Comments