Monday, June 29, 2009

StringBuilder vs. StringBuffer

A tip on StringBuilder vs. StringBuffer

  • We should be using StringBuilder over StringBuffer. It’s a drop-in replacement, all the method names and arguments are the same.

  • StringBuilder is not synchronized and therefore doesn’t require object locks everytime a method is called. The only time we’d use StringBuffer is when it’s a member variable with a possibility of multiple threads writing to it.

No comments:

Post a Comment