0

I have mulitthreaded programs that read large xmls and currently convert them to String e.g:

String temp = MyObject.convertToString(xmls);

i have to pass on this String to various methods to process it. The Question is not related to appending BUT holding/Storing this large text in an Object i.e String OR StringBuilder.

How String and StringBuilder will affect performance/memory, my thinking is that if i keep using String it will pool the string in JVM with multiple XMLS. In other case it will be an Object and will be GC'd once not required or set to null. More over what will be the behavior of Stringbuilder.toString() on memory then.

2
  • you can use StringBuilder to read it easily. Commented Feb 23, 2017 at 6:24
  • StringBuilder's purpose to build or manipulate string. If you do not manipulate your string then use string. If you worried about performence/memory of keeping and reading string - definitely use a string Commented Feb 23, 2017 at 6:28

1 Answer 1

1

it will pool the string in JVM with multiple XMLS

Only if it's a string literal or you intern() it. No reason not to use a String here.

Sign up to request clarification or add additional context in comments.

2 Comments

that makes sense, now what will be the affect of StringBuilder.toString(), how will it look in back ground, if i used builder and then did toString() on it every time.
I don't know what you mean by 'in background', but the result of toString() is a String, to which the remarks in this answer apply. As you're not appending, I don't even know why you're asking the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.