From the course: Intermediate Kotlin for Android Developers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Arrays

Arrays

From the course: Intermediate Kotlin for Android Developers

Start my 1-month free trial

Arrays

- [Instructor] Arrays in Kotlin are classes with a type parameter. In this example, we have an arrayOf ints, initialized with the values one, two, and three. Now if we wanted to do the same thing in Java just as a comparison, we'd define it this way with the type followed by brackets and then the name. In fact, these two things are comparable because the default array class creates boxed representations of the types. We just saw one way to initialize an array in Kotlin with the arrayOf function. But you can also use the array function with your desired size of the array as well as a lambda which can initialize each element. In this example, we're creating an array of strings with the size of two and then setting each value to an empty string. You can also use the arrayOfNulls function if you want to create an array of a particular size with null elements. In this case, we created an array of strings with two null values, then set the first one to another string. So if we print them…

Contents