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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -