This article explores different ways to create an empty array in Kotlin.

1. Using emptyArray() function

The standard way to get an empty array is to use the emptyArray() function.

Download Code

 
This can be shortened to:

Download Code

2. Using arrayOf() function

If you need an empty array instance, you can also use the arrayOf() function with no values.

Download Code

 
We can simplify the declaration to:

Download Code

3. Using arrayOfNulls() function

You can get an empty array of nulls using the arrayOfNulls function.

Download Code

 
Similar to the previous approach, we can rewrite this as:

Download Code

4. Using Array Constructor

Finally, you can use the Array constructor to get an empty array, as shown below:

Download Code

That’s all about creating an empty array in Kotlin.