i <= maxlength replace this with i < maxlength .
The array index starts from zero, not from one. Thus, the length of the array is one less than the final index of the array. When you use <=, you are trying to jump to one element after the last element in your array. Therefore, this is an exception.
Also you need to check the length of array b. If the length of the array b is less than a, you will encounter the same exception.
int maxlength = Math.min( this.length, b.length ); more suitable.
Or, if you do not want to skip any elements in any of the arrays when adding, an ArrayList is the answer for you. ArrayList is the self-expanding array you are looking for. Here is how you can do it -
source share