GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 141 of 502    Print  
What is the difference between String and StringBuffer? Which is better to use in project?

  
Total Answers and Comments: 15 Last Update: February 05, 2009     Asked by: Devidas 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
October 25, 2005 07:37:20   #1  
venkatram reddy        

RE: What is the difference between String and StringBu...

String buffer is a mutable string object. String is a non - mutable object. When we say mutable means which can be changed anytime. Its better to string buffer if we want to modify a string from multiple threads(Some places synchronization is required).


 
Is this answer useful? Yes | No
October 25, 2005 07:37:39   #2  
venkatram reddy        

RE: What is the difference between String and StringBu...

String buffer is a mutable string object. String is a non - mutable object. When we say mutable means which can be changed anytime. Its better to string buffer if we want to modify a string from multiple threads(Some places synchronization is required).


 
Is this answer useful? Yes | No
October 30, 2005 01:38:02   #3  
SRIRAM.N.SHARMA        

RE: What is the difference between String and StringBu...

When a String is created it is not destroyed. It remains in the pool of memory and whenever that string is referred the JVM searches for the String from the string pool of memory and gets the relevant data. So as such String is expensive operation.

String buffer can be changed/modified based on our requirement. There are chances that you may need to form a query based on some conditions. Such queries can be formed using String buffer. Finally you can user the toString method to get the final String version of the stringBuffer.

Pls mail back if you are unclear with any of the items that I have specified in this solution.

Thanks & Regards

Sriram


 
Is this answer useful? Yes | No
October 31, 2005 03:24:34   #4  
Manikant        

RE: What is the difference between String and StringBu...
String is immutable whereas StringBuffer is mutable.
 
Is this answer useful? Yes | No
October 31, 2005 03:25:29   #5  
Manikant        

RE: What is the difference between String and StringBu...
String is immutable whereas StringBuffer is mutable.
 
Is this answer useful? Yes | No
November 03, 2005 02:29:20   #6  
justAnother        

RE: What is the difference between String and StringBu...

I just read a discussion in the following article (about String vs Stringbuffer). It contridicts popular belief and so it is interesting.

http://thedailywtf.com/forums/41017/ShowPost.aspx

Hope that is informative/ interesting.

- justAnother


 
Is this answer useful? Yes | No
November 06, 2005 09:49:46   #7  
jagadeesh meduri        

RE: What is the difference between String and StringBu...

RE: What is the difference between String and StringBu...


 
Is this answer useful? Yes | No
November 10, 2005 07:39:35   #8  
sekhar babu        

RE: What is the difference between String and StringBu...
String class objects are immutable(not change).StringBuffer class objects are mutable(change).In our project for constants use String class object for variables use StringBuffer class object then performance will be increased.
 
Is this answer useful? Yes | No
November 11, 2005 16:47:44   #9  
mandyjoshi Member Since: November 2005   Contribution: 20    

RE: What is the difference between String and StringBu...

String is immutable. If you want to update string value often (build query on condition) you should use StringBuffer.

for(int i 0;i<100;i++)

{

}


 
Is this answer useful? Yes | No
November 11, 2005 16:50:40   #10  
mandyjoshi Member Since: November 2005   Contribution: 20    

RE: What is the difference between String and StringBu...

String is immutable. If you want to update string value often (build query on condition) you should use StringBuffer.

method(){

String abc ;

for(int i 0;i<100;i++)

{

abc abc + d ; // each time new string object is formed. very expensive

}}


 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape