"Testing1"
Kotlin Arrays
What is an Array?
An array is a single structure that stores several similar elements in an ordered sequence.
val fruits = arrayOf("Apple", "Banana", "Cherry")
Why Use Arrays?
They help you store several values in one structure without creating many variables.
Accessing Elements
You can reach any item by its position (starting from zero):
println(fruits[0]) // Outputs: Apple
Modifying Values
Change a value by pointing to its index:
fruits[1] = "Blueberry"
Size of Array
Know how many things are inside:
println(fruits.size) // Outputs: 3
Loop Through Items
Check or use each value using a loop:
for (item in fruits) {
println(item)
}
Create Specific Types
Arrays can also hold numbers or other types:
val numbers = arrayOf(10, 20, 30)
Val letters = arrayOf('A', 'B', 'C')
Empty Array
Start with an empty list if needed:
val emptyArray = emptyArray<String>()
Prefer Learning by Watching?
Watch these YouTube tutorials to understand KOTLIN Tutorial visually:
What You'll Learn:
- 📌 #40 Kotlin Tutorial | Array
- 📌 Kotlin Tutorial for Beginners - Kotlin Array (With Example)