Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Buffer: Size or Length?

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

Both size and length methods are defined, inherited from separate traits.

Is there any actual performance difference, or can they be considered exact synonyms?

like image 326
Eduardo Avatar asked Feb 06 '13 16:02

Eduardo


1 Answers

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.

like image 122
Daniel C. Sobral Avatar answered Oct 02 '22 18:10

Daniel C. Sobral