title: Java - Iterate over a 2-dimensional array starting with the middle
body: <p>I have this totally normal loop over a 2 dimensional array.</p>
  
  <pre><code>for(int i = 0; i&lt;array.length; i++){
      for(int j = 0; i&lt;array.length; j++){
          array[i][j].doSomething();
      }
  }
  </code></pre>
  
  <p>I want to go through this 2 dimensional array, starting in the middle. For example, if the array has a length of 100 for both dimensions, I want it to go over it like this:</p>
  
  <pre><code>array[50][50] //middle of array
  array[49][50] //x-1
  array[50][49] //y-1
  array[51][50] //x+1
  array[50][51] //y+1
  array[48][50] //x-2
  array[49][49] //x-1 and y-1
  array[50][48] //y-2
  array[51][49] //x+1 and y-1
  array[52][50] //x+2
  array[51][51] //x+1 and y+1
  array[50][52] //y+2
  array[49][51] //x-1 and y+1
  etc.
  </code></pre>
  
  <p>I've been spending hours on finding an efficient way and finding a solution on the internet, but I haven't found a great answer yet. Anyone who knows how to do this?</p>