| Author |
is there a maximum length for java.lang.String?
|
Joe Boxer
Greenhorn
Joined: Oct 23, 2003
Posts: 15
|
|
hi, just wondering if there is a maximum length of characters we can assign to a varaible of the type String? cheers Joe
|
 |
Stefan Krompass
Ranch Hand
Joined: Apr 29, 2004
Posts: 75
|
|
Hi, the boundary is 2^31-1 characters, since the getLength()-method of String returns an int-value. The other boundary is your RAM. So your String is limited by the boundary that is reached first. cu Stefan
|
 |
Tim West
Ranch Hand
Joined: Mar 15, 2004
Posts: 539
|
|
There is one other limitation, though it would only come up rarely in practice: current Sun compilers don't like literal strings (like String s = "foo") over 65535 characters long. This was discussed somewhere on JavaRanch a month or two back, I remember writing a quick program to confirm it. In practical terms, RAM limitations crop up before int overflow errors. With repeated doubling of String length, think I crashed my JVM at length of around 2^23. Cheers, --Tim [ May 04, 2004: Message edited by: Tim West ]
|
 |
 |
|
|
subject: is there a maximum length for java.lang.String?
|
|
|