Yahoo India Web Search

Search results

  1. Dec 10, 2008 · StringBuilder and StringBuffer are almost the same. The difference is that StringBuffer is synchronized and StringBuilder is not. Although, StringBuilder is faster than StringBuffer, the difference in performance is very little. StringBuilder is a SUN's replacement of StringBuffer. It just avoids synchronization from all the public methods.

  2. Jun 4, 2010 · Thread-Safety Difference: The difference between StringBuffer and StringBuilder is that StringBuffer is threadsafe. So when the application needs to be run only in a single thread, then it is better to use StringBuilder. StringBuilder is more efficient than StringBuffer. Situations: If your string is not going to change use a String class ...

  3. Mar 26, 2011 · Beyond the simple question (StringBuffer is more efficient than "+" and thread-safe, and StringBuilder is faster than StringBuffer but no thread-safe) I would like to know when to use them. (Important: I know the differences between them; this is a question related to the architecture of the platform and some design decisions.)

  4. Mar 17, 2010 · In contrast StringBuffer (and std::string) is the equivalent of a dynamic array of chars. Appending to it is O* (1). Worst case of append is O (n) but k consecutive calls to append lead to k.O (1) operations => O* (1). Read more about amortized complexity analysisof insertion into dynamic array.

  5. Mar 4, 2011 · 34. If you look at the source code for a StringBuilder or StringBuffer the setLength () call just resets an index value for the character array. IMHO using the setLength method will always be faster than a new allocation. They should have named the method 'clear' or 'reset' so it would be clearer.

  6. Sep 16, 2008 · System.Console.WriteLine("Using StringBuilder: " + time.ElapsedMilliseconds + " milliseconds"); Result: Using StringBuilder: 10 milliseconds. As a result, the first iteration took 15423 ms while the second iteration using StringBuilder took 10 ms. It looks to me that using StringBuilder is faster, a lot faster.

  7. Aug 3, 2010 · As of Java 8, the String class has a static method join.The first argument is a string that you want between each pair of strings, and the second is an Iterable<CharSequence> (which are both interfaces, so something like List<String> works.

  8. Sep 29, 2016 · To recycle an existing StringBuilder or StringBuffer, simply call setLength(0). Edit You can overwrite a range of elements with the replace() function. To change the entire value to newval, you would use buffer.replace(0,buffer.length(),newval). See also: StringBuilder; StringBuffer

  9. Jan 26, 2013 · In addition to K.S's response of creating a StringBuilderPlus class and utilising ther adapter pattern to extend a final class, if you make use of generics and return the StringBuilderPlus object in the new append and appendLine methods, you can make use of the StringBuilders many append methods for all different types, while regaining the ability to string string multiple append commands together, as shown below

  10. May 27, 2010 · The StringBuilder class should generally be used in preference to this one, as it supports all of the same operations but it is faster, as it performs no synchronization. Basically StringBuffer can be used by multiple threads at the same time, since it's synchronized, but that also makes it a bit slower than StringBuilder which can only be used by one thread at a time.

  1. People also search for