What is the main difference between StringBuffer and StringBuilder?

Technology CommunityCategory: JavaWhat is the main difference between StringBuffer and StringBuilder?
VietMX Staff asked 4 years ago
  • StringBuffer is synchronized, StringBuilder is not. When some thing is synchronized, then multiple threads can access, and modify it with out any problem or side effect. StringBuffer is synchronized, so you can use it with multiple threads with out any problem.
  • StringBuilder is faster than StringBuffer because it’s not synchronized. Using synchronized methods in a single thread is overkill.