Difference between String and stringBuffer in java

 

Difference between String and stringBuffer in java

Or 

String versus StringBuffer


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="om"; 


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("om"); 


Comments

Popular posts from this blog

Applets - Inheritance hierarchy for applets, differences between applets and applications, life cycle of an applet, passing parameters to applets, applet security issues.

Control Statements:Selection statement ,Iteration statement and Jump statement in Java

Write a java program to demonstrate static variable, methods, blocks.