title: What are the weaknesses and shortcomings of arrays?
body: <p>I would like to know what are the weaknesses of the arrays. I think that it is very helpful to know in order to determine whether the arrays are the best way to store the data in particular situation, or to predict the time of execution. </p>
  
  <p><strong>Edit 1:</strong> Clarification, by arrays as I understand them:</p>
  
  <ol>
  <li>Not <strong>finite</strong>, but <strong>fixed size storage</strong>, that is used as <strong>sequential data containers</strong>, that are <strong>mutable</strong>. 1 or more <strong>indexes</strong> are used to <strong>reference</strong> a specific data container. 
  <ol>
  <li>Data contained must be of <strong>same type</strong>, if the type is <strong>primitive</strong>.</li>
  <li>Data contained must be of <strong>same data type</strong> or <strong>descendant</strong> of the type, if type is object (this is <strong>polymorphism</strong>), this kind of type <strong>conversion</strong> is <strong>narrower to wider</strong> also called <strong>covariant</strong> conversion.</li>
  <li><strong>All arrays</strong> in Java are <strong>1 dimensional arrays</strong>.</li>
  <li><strong>Swapping</strong> elements or <strong>finding element with its indexes</strong> is <strong>fast</strong> operation</li>
  <li><strong>Adding/Removing</strong> elements is <strong>slow</strong> operation, as array is recreated</li>
  <li><strong>Element types</strong> are <strong>enforced</strong> at runtime, this is called arrays are <strong>reified</strong>.</li>
  <li>Java array methods are in <code>java.util.Arrays</code> and thy do not even contain basic array manipulation methods like <strong>union</strong> and <strong>intersection</strong>. Its sad, that guava-libraries is not part of standard Java.</li>
  <li>Object array is filled with <strong>references</strong> to storage locations where the data actually is.</li>
  </ol></li>
  <li><strong>Array of arrays</strong> is called <strong>2 dimensional array</strong>. 
  <ol>
  <li>2d arrays first array is filled with <strong>references</strong> to other arrays. </li>
  <li>Other arrays are not stored sequentially.</li>
  <li>Other arrays can vary in element size, this is called <strong>ragged</strong>- and <strong>jagged arrays</strong>.</li>
  <li>Java arrays have <strong>row-major order</strong>.</li>
  <li>Array <strong>dimension</strong> is typically <strong>limited to 255</strong>, but it varies from implementation.</li>
  </ol></li>
  <li><p>Exceptions and important notes.</p>
  
  <ol>
  <li>In case of managed memory environment, the <strong>absolute locations</strong> of data elements <strong>can be sequential</strong>, but most likely are not.</li>
  <li>Arrays used directly can't be <strong>threadsafe</strong>, <strong>immutable</strong> or <strong>have transactional integrity</strong> and because of this, there is no direct way to go <strong>parallel</strong>.</li>
  <li>If you need to find if specific data is contained in <strong>sorted array</strong> you can use <strong>binary search</strong>, that is not much slower then <strong>hashset.contains</strong> what I assume uses <strong>VMMemoryManager.getIdentityHashCode</strong>, that is basically just old school <strong>modulation calculus</strong> and where <strong>collisions can happen</strong>. </li>
  <li>Java <strong>generics</strong> is just <strong>compiler magic</strong>, but if you want to use <strong>Java generic</strong> with arrays, then you can't use <strong>primitive types</strong>.</li>
  <li>In Java 6, <strong>Collections.sort()</strong> works like - dump data in array and ... - at that point difference is x2 times in memory.</li>
  <li><strong>Garbage collector</strong> really does not like arrays, and thy usually end up in <strong>old generation</strong>, and wont be freed any soon. </li>
  <li>It's a bad idea to enter <strong>big</strong> data <strong>elements</strong> in arrays, but i can't remember why.</li>
  </ol>
  
  <p>In my opinion arrays are one of very best ways to store data, just not directly. At times, my head seems to be like a garbage bin, where knowledge is malformed. This is one reason why I asked this question - to confirm what i know.</p></li>
  </ol>