Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Difference between String & StringBuffer

Answer Posted / sathish

Here the compiler does a good job of optimization. Compiler
simply concatenates at compile time as
shown below. It does compile time resolution instead of
runtime resolution, this happens when you
create a String object using 'new' key word.
before compilation:
String result = "This is"+"testing
the"+"difference"+"between"+"String"+"and"+"StringBuffer";
after compilation
String result = "This is testing the difference between
String and StringBuffer";
String object is resolved at compile time where as
StringBuffer object is resolved at run time. Run time
resolution takes place when the value of the string is not
known in advance where as compile time
resolution happens when the value of the string is known in
advance. Here is an example.
Before compilation:
public String getString(String str1,String str2) {
return str1+str2;
}
After compilation:
return new StringBuffer().append(str1).append(str2).toString();
This resolves at run time and take much more time to execute.

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Describe different states of a thread.

997


What is user defined exception in Java?

1067


What is the gregoriancalendar class in java programming?

1029


What is an argument java?

963


Why 1 is not a prime number?

1022


What is a final class in java?

1003


What is general methodology?

1031


What is %02d?

1077


What is the purpose of the runtime class in java programming?

1051


How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?

956


What's the base class of all exception classes?

1057


Explain different types of wrapper classes in java?

1009


What is the default size of arraylist in java?

1112


What are the types of collections in java?

1048


What will happen to the exception object after exception handling?

989