.size
Anonymous contributor
Published Nov 23, 2024
Contribute to Docs
In Kotlin, the .size
property calculates the number of elements in an array.
Syntax
arr.size
arr
: The array whose size is to be accessed.
Example
The following example demonstrates the usage of the .size
property:
fun main() {// Creating an arrayval arr = intArrayOf(1, 7, 14, 21, 28, 35)// Calculating the number of elements in the arrayval num = arr.size// Printing the resultprintln("$num")}
The above code produces the following output:
6
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Kotlin on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Kotlin
Learn Kotlin, the expressive, open-source programming language developed by JetBrains.Beginner Friendly9 hours