String character limit
I am developing an application that sends a String over a socket, but I have not set a limit on the size of the string. Is there a limit to the size of a string in characters or bytes in java? What about sending a very large string (millions of characters) over a socket? Is there a limit?
source to share
The number of characters in a string is determined by the maximum size of an array in Java. This is Integer.MAX_VALUE (2 147 483 647). You will most likely run out of RAM before you hit that limit.
There is no limit to the number of characters that can be sent over the Socket.
If your data structure allows you, you may be given the option to work with the streaming API. for example if a string is being output from the db or from disk it runs it on a socket when you read it into memory. This way you don't need to hold the entire string in memory.
source to share