Forums Register Login

Strings

+Pie Number of slices to send: Send
Hi everyone,

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?

I hope someone can help me with this

Thank You

Yours Sincerely

Richard West
+Pie Number of slices to send: Send
As far as I understand there is NO limit to the size of String. Obviously, you have the limitation in VM's heap size.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
If you think you need to have a String object with 5 to 50 million characters, then most likely you need to re-think the design of your program.
+Pie Number of slices to send: Send
Hi everyone,

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
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
https://gardener-gift.com


reply
reply
This thread has been viewed 977 times.
Similar Threads
Cookie value
DOS Script - Websphere
GC
StringBuffer/StringBuilder question - unexpected results
Replace a character with characters
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:38:15.