Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Considering the <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html" rel="noreferrer"><code>String</code></a> class' <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#length()" rel="noreferrer"><code>length</code></a> method returns an <code>int</code>, the maximum length that would be returned by the method would be <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#MAX_VALUE" rel="noreferrer"><code>Integer.MAX_VALUE</code></a>, which is <code>2^31 - 1</code> (or approximately 2 billion.)</p> <p>In terms of lengths and indexing of arrays, (such as <code>char[]</code>, which is probably the way the internal data representation is implemented for <code>String</code>s), <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html" rel="noreferrer">Chapter 10: Arrays</a> of <a href="http://docs.oracle.com/javase/specs/jls/se7/html/index.html" rel="noreferrer">The Java Language Specification, Java SE 7 Edition</a> says the following:</p> <blockquote> <p>The variables contained in an array have no names; instead they are referenced by array access expressions that use nonnegative integer index values. These variables are called the <em>components</em> of the array. If an array has <code>n</code> components, we say <code>n</code> is the <em>length</em> of the array; the components of the array are referenced using integer indices from <code>0</code> to <code>n - 1</code>, inclusive.</p> </blockquote> <p>Furthermore, the indexing must be by <code>int</code> values, as mentioned in <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.4" rel="noreferrer">Section 10.4</a>:</p> <blockquote> <p>Arrays must be indexed by <code>int</code> values;</p> </blockquote> <p>Therefore, it appears that the limit is indeed <code>2^31 - 1</code>, as that is the maximum value for a nonnegative <code>int</code> value.</p> <p>However, there probably are going to be other limitations, such as the maximum allocatable size for an array.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload