Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMukul Gupta
8,760 PointsStringBuffer
According to the API documentation for Date, format() returns an item of StringBuffer type. What is StringBuffer and how is it different from String?
1 Answer
adamabdulghani
7,864 PointsStringBuffer is faster than String when it comes to concatenations, so if you have a lot of concats. to do then you should use StringBuffer
StringBuffer sb = new StringBuffer("Mukul");
for(int i =0 ; i<50 ; i++){
sb.append(" Gupta");
} // This would be faster than myString+=" Gupta";
String longName = sb.toString(); // to convert from StringBuffer to String use toString() method