Menu
Coddy logo textTech

Recap Challenge #3

Lesson 16 of 16 in Coddy's Strings and Arrays in Java course.

To declare an empty array of size n,

int[] newArr = new int[n];

Now you can access and modify elements inside the array (as long as it's not exceeding n size):

By default, the array of integers is filled with 0s.

The full syntax is:

type[] arrayName = new type[arraySize];
challenge icon

Challenge

Medium

Write a function named combineArrays that gets two arrays of integers, combines them into one, and returns the new array.

For example,

Input: [1, 2, 3], [1, 3, 5]

Expected output: [1, 2, 3, 1, 3, 5]

Try it yourself

class CombineArrays {
    public static int[] combineArrays(int[] a1, int[] a2) {
        // Write code here
    }
}

All lessons in Strings and Arrays in Java