What is the Kotlin equivalent to Java’s .length()? Also, how do you use Kotlin’s size and length functions?
Its the same thing, but it might suggest using a propert accessor so arr.length
or arr.size
The form may not be the best place to ask these small questions if you’re wanting quick responses. I’d recommend reading the reference: http://kotlinlang.org/docs/reference/
Or maybe going through the Kotlin Koans using the web IDE: Kotlin Playground: Edit, Run, Share Kotlin Code Online
I would say count is the kotlin-alternative.
It works on objects that have the size and length property.
Count and Length / size is something different. IMHO count can actually count the elements (e.g. on an iterable iterate through everything), but length / size can work with stored values…
You can see size/length as an implementation of count.
So you’re correct.
But I don’t think it’s very different (although the implementation may be other than O(1)).
Most of the time count just refers to size or length, depending on which method the class has