ArrayBuffer vs ArrayBuilder in scala -
what difference between scala.collections.mutable.arraybuilder , scala.collections.mutable.arraybuffer? if, instance, need build array[int], preferrable use? there perfomance difference, in java.lang.stringbuffer , java.lang.stringbuilder?
arraybuilder
builder
, , builders meant used construct other collections adding elements them. builders not meant used directly in client code.
arraybuffer
buffer
, seq
-- buffers sequences can efficiently append elements. sequences come lot of auxiliary operations.
you need arraybuffer
. meant used alternative arraylist
in java. arraybuffer
class fully-powered sequence collections bulk data operations foreach
, map
, filter
, zip
, friends, unlike arraybuilder
equipped +=
add elements , result
obtain array @ end.
one place might prefer arraybuilder
when instantiating primitive type int
, care performance. in case arraybuilder
variants specialized different primitive types , hold underlying array of proper primitive type, whereas arraybuffer
holds object array underneath -- every primitive add undergoes boxing.
to instantiate array buffer:
new arraybuffer[int] // gives array buffer hold boxed integers
to instantiate array builder:
new arraybuilder.ofint // gives manually specialized array builder hold real primitives
Comments
Post a Comment