I have a rather silly question but what is the maximum amount of characters the String object can hold?
This is what i mean
What i am afraid is that if the String object may throw an exception if i return a huge string object say something down the lines of 5-50 million characters as a string. Will there be stack overflow?
No stack overflow since no stack is involved. Limit is 2 gigabytes: String length() returns an int and that's your limit. You will exhaust your memory before you exhaust the upper limit of a String. If you have more than a 10K string I suggest looking at alternative strategies to manage that memory.
The reason why i am using the string in this way is because the object that is returning the huge string is a document.
Why i need this is because i use this method to search the document for a certain string. Everything works but i am afraid that if the document returns a huge string from the document, i may actually exceed the limit.
On another issue i also felt that because the String object is immutable would it be better if i use the StringBuffer class as that does not create a copy of the string something like that
Would tis actually make a difference in that the String object is immutable and the StringBuffer object is mutable?
Any help is greatly appreciated
Thank You
Yours Sincerely
Richard West
Post by:autobot
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
a bit of art, as a gift, the permaculture playing cards