title: How to sort a 2 dimensional array with all elements in ascending order in java
body: <p>Is there any efficient way to sort a 2 dimensional array in java like using <code>Arrays.sort()</code>.For ex:-</p>
  
  <pre><code>a={{3 ,1},{0,2})
  result={{0,1},{2,3}}
  </code></pre>
  
  <p>This was my approach:</p>
  
  <pre><code>  for (int x = 0; x &lt; n; x++) {
        for (int y = 0; y &lt; n; y++) {
              for (int i = 0; i &lt; n; i++) {
                  for (int j = 0; j &lt; n; j++) {
                      if (grid[i][j] &gt; grid[x][y]) {
                          int t = grid[x][y];
                          grid[x][y] = grid[i][j];
                          grid[i][j] = t;
                      }
                  }
              }
          }
      }
  </code></pre>