CharBuffer vs. StringBuffer

Performance of java.nio.CharBuffer vs. java.lang.StringBuffer:




  % diff 









For “normal” string processing there appears to be no difference between the two — the effects are lost in the noise. For large strings (documents and the like), CharBuffer has a distinct advantage.

CharBuffer has the perk of pointer-like manipulation via CharBuffer.subSequence() and CharBuffer.slice() but lacks good string searching functions like StringBuffer.lasIndexOf().

The only caveat with CharBuffer is that the size of the buffer must be known a priori.


  • The length of the strings added were between 0 and 10 characters in length to simulate standard text processing.
  • This should be taken with a grain of salt since it is a micro-benchmark.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s