Hi all, I want to create a XML string from a XML. Is it ok, if i use StringBuffer for this purpose. The idea is, go on appending the required data to the StringBuffer and finally convert the StringBuffer to String. I am worried about one thing. If the XML is a bit large, does it affects the performance or is there any memory issue. Please advice. Thanks
If you think you can, you can. If you think you can't, you are right.
You can also use the StringBuilder class for such operations. StringBuilder is faster than StringBuffer but not syncronized. In single threaded environment you can very well use the StringBuilder to gain performance improverments
If you are sure the length is going to be very large and have an approximation of its length, you may use the following constructor StringBuffer(int length) to avoid allocation of a new internal buffer array when internal buffer overflows as stated in the Java docs.