Scala Buffer: Size or Length?

后端 未结 4 1717
無奈伤痛
無奈伤痛 2021-01-08 01:20

I am using a mutable Buffer and need to find out how many elements it has.

Both size and length methods are defined, inherited

4条回答
  •  再見小時候
    2021-01-08 02:01

    They are synonyms, mostly a result of Java's decision of having size for collections and length for Array and String. One will always be defined in terms of the other, and you can easily see which is which by looking at the source code, the link for which is provided on scaladoc. Just find the defining trait, open the source code, and search for def size or def length.

提交回复
热议问题