Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>AFAIK the only way of growing or reducing an array is doing a System.arraycopy</p> <pre><code> /** * Removes the element at the specified position in this list. * Shifts any subsequent elements to the left (subtracts one from their * indices). * * @param index the index of the element to removed. * @return the element that was removed from the list. * @throws IndexOutOfBoundsException if index out of range &lt;tt&gt;(index * &amp;lt; 0 || index &amp;gt;= length)&lt;/tt&gt;. */ public static &lt;T&gt; T[] removeArrayIndex(T[] src, int index) { Object[] tmp = src.clone(); int size = tmp.length; if ((index &lt; 0) &amp;&amp; (index &gt;= size)) { throw new ArrayIndexOutOfBoundsException(index); } int numMoved = size - index - 1; if (numMoved &gt; 0) { System.arraycopy(tmp, index + 1, tmp, index, numMoved); } tmp[--size] = null; // Let gc do its work return (T[]) Arrays.copyOf(tmp, size - 1); } /** * Inserts the element at the specified position in this list. * Shifts any subsequent elements to the rigth (adds one to their indices). * * @param index the index of the element to inserted. * @return the element that is inserted in the list. * @throws IndexOutOfBoundsException if index out of range &lt;tt&gt;(index * &amp;lt; 0 || index &amp;gt;= length)&lt;/tt&gt;. */ public static &lt;T&gt; T[] insertArrayIndex(T[] src, Object newData, int index) { Object[] tmp = null; if (src == null) { tmp = new Object[index+1]; } else { tmp = new Object[src.length+1]; int size = tmp.length; if ((index &lt; 0) &amp;&amp; (index &gt;= size)) { throw new ArrayIndexOutOfBoundsException(index); } System.arraycopy(src, 0, tmp, 0, index); System.arraycopy(src, index, tmp, index+1, src.length-index); } tmp[index] = newData; return (T[]) Arrays.copyOf(tmp, tmp.length); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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