Possible Duplicate:
count vs length vs size in a collection
In Java in particular, on Strings
, you call string.length()
, whereas in Lists
you call list.size()
. Is there a technical difference between the two terms, seeing as a String
is really just a list of chars
?
Any comments appreciated.
In general, length() is used when something has a constant length, while size() is used on something with a variable length. Past that, I know of no good reason for using two nearly-synonymous terms.
Ideally, count
would be the number of items, and size
would be the amount of storage taken up (as in sizeof
).
In practice, all three (including length
, which is the most ambiguous) are muddled up in many widely-used libraries, so there's no point trying to impose a pattern on them at this stage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With