Monday, May 24, 2010

Java equivalent to System.Text.StringBuilder in C#?

I want to build a very large string from lots and lots of small strings. In C# I would use System.Text.StringBuilder without hesitation. At present I am using java.io.StringWriter, but I am concerned that it may not be efficient enough? Is there a better option? MUST be FAST! Thanks in advance.

Java equivalent to System.Text.StringBuilder in C#?
That is not what StringWriter is for. StringWriter is a character-based output stream that writes the bytes to memory.





Use java.lang.StringBuilder. It was added in Java 5 (JDK 1.5). It is similar to java.lang.StringBuffer, but without the synchronization. So, if you plan on designing your program such that only one thread will be using it, use the StringBuilder.


No comments:

Post a Comment