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");


 

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation