I'm writing a custom hashmap implementation that is backed by a matrix (2D array). I want to iterate through the elements and print them, but want to avoid printing null elements. 

The hashmap only supports Integers and calculates the hashcodes as input mod 10. It will store these Integers inside the appropriate hashcode index, and collisions are resolved by iterating through the subarray and placing the Integer in the next available index of the subarray. If the maximum index of a given subarray is exceeded, it will create a new array of size 1.5x the original and copy the elements over to that.

The problem is that `System.out.print` will throw an `ArrayIndexOutOfBoundsException` every time when `iterator` is equal to the subarray length, so the while loop is not working as expected.

I've already tried changing the while loop such that the iterator variable is supposed to be less than the maximum index of each subarray. Changing the condition to `iterator < array[i].length - 1` will avoid the exception but Java will not print the last element of each subarray.

```java
public void print () {
        int iterator = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] == null)
                continue;
            System.out.print("[");
            while (array[i][iterator] != null && iterator < array[i].length) {
                System.out.print(array[i][iterator] + ", ");
                iterator++;
            }
            System.out.println ("]");
            iterator = 0;
        }
    }

```

The output is supposed to be something like

```
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, ]
[1, 11, 21, 31, 41, 51, 61, 71, 81, 91, ]...

```

But the actual output is 

```
[0, 10, 20, 30, 40, 50, 60, 70, 80, 90, Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
    at regularexpression.HashMap.print(HashMap.java:42)

```