2017-10-13

Difference between StringBuffer and StringBuilder

Difference between StringBuffer and StringBuilder

StringBuilder vs StringBuffer

  • Both are mutable classes
  • StringBuffer is that it is synchronized which means it is  thread-safe
  • slow than StringBuilder
  • StringBuilder is not synchronized it is faster than StringBuffer

Example of StringBuilder and StringBuffer:

StringBuffer strBuffer = new StringBuffer("Test Example");
strBuffer.append("1");

StringBuilder strBuilder = new StringBuilder("Test Example");
strBuilder.append("2");


 

No comments:

Post a Comment