title: I need to get all even numbers from random length 2D Array and make another 2D array with even numbers I've got
body: <p>My Java code get all numbers I need, but every row in new array have length like in old array. How to make array with different row length only for numbers I've got?</p>
  <p>Please check for my code:</p>
  <pre><code>import java.util.Arrays;
  import java.util.Random;
  
  public class Help {
      public static void main(String[] args) {
          Random random = new Random();
          int n = random.nextInt(10);
          int m = random.nextInt(10);
          if (n &gt; 0 &amp;&amp; m &gt; 0) {
              int[][] arr = new int[n][m];
              for (int i = 0; i &lt; arr.length; i++) {
                  for (int j = 0; j &lt; arr[i].length; j++) {
                      arr[i][j] = random.nextInt(20);
                      System.out.print(arr[i][j] + &quot; &quot;);
                  }
                  System.out.println();
              }
              System.out.println();
              System.out.println(&quot;***** EvenMatrix *****&quot;);
              int[][] evenMatrix = new int[n][m];
              int evenElement = 0;
              for (int i = 0; i &lt; arr.length; i++) {
                  for (int j = 0; j &lt; arr[i].length; j++) {
                      if (arr[i][j] % 2 != 0) {
                          continue;
                      } else
                          evenElement = arr[i][j];
                      for (int k = 0; k &lt; arr[i].length; k++) {
                          evenMatrix[i][j] = evenElement;
                      }
                      System.out.print(evenMatrix[i][j] + &quot; &quot;);
                  }
                  System.out.println();
  
              }
              System.out.println(Arrays.deepToString(evenMatrix));
  
          } else {
              System.out.println(&quot;Incorrect array length! Try again!&quot;);
              System.exit(0);
  
          }
      }
  }
  </code></pre>