Home arrow static arrow Java Programming [Archive] - String Length
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - String Length
This topic has 2 replies on 1 page.

Posts:37
Registered: 7/21/03
String Length  
Jul 12, 2004 7:01 PM



 
Hi,

I was wondering......How long can a String be?

I was looking through one of the String*.. classes it had an initial capacity of datatype int. What if i put a value greater than the int's Max value.

-Thanks
 

Posts:2,067
Registered: 5/3/01
Re: String Length  
Jul 12, 2004 7:46 PM (reply 1 of 2)



 
Hi,

I was wondering......How long can a String be?

I was looking through one of the String*.. classes it
had an initial capacity of datatype int. What if i put
a value greater than the int's Max value.

-Thanks

It is also backed by a char array which (according to the Java Language Spec -- accent added):

10.4 Array Access
A component of an array is accessed by an array access expression (�15.13) that consists of an expression whose value is an array reference followed by an indexing expression enclosed by [ and ], as in A[i]. All arrays are 0-origin. An array with length n can be indexed by the integers 0 to n-1.
Arrays must be indexed by int values; short, byte, or char values may also be used as index values because they are subjected to unary numeric promotion (�5.6.1) and become int values. An attempt to access an array component with a long index value results in a compile-time error.

All array accesses are checked at run time; an attempt to use an index that is less than zero or greater than or equal to the length of the array causes an ArrayIndexOutOfBoundsException to be thrown.
 

Posts:2,909
Registered: 13.8.2003
Re: String Length  
Jul 12, 2004 10:46 PM (reply 2 of 2)



 
...so that would be 2^31 characters long taking 4 gigabytes of memory.
 
This topic has 2 replies on 1 page.