Hey everyone! :wave: I often get confused between ...
# getting-started
b
Hey everyone! 👋 I often get confused between using
.size
and
.length
in Kotlin. Sometimes they are properties, sometimes functions — and it's not always clear which to use for what type. For example: •
String
uses
.length
Array
and
List
use
.size
StringBuilder
uses
.length()
(function) • Is there a consistent rule or guideline in Kotlin for when to use
.size
vs
.length
, and when it's a property vs a function? Would love to hear how others mentally organize this! Thanks in advance 🙏
c
For your own code, always use
.size
.
.length
in
String
and
StringBuilder
are legacy decisions that were inherited from Java for better interoperability