- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Where to use a StringBuffer/StringBuilder than a String in Java?
- The String class objects are immutable whereas the StringBuffer and the StringBuilder objects are mutable.
- A StringBuffer is synchronized while a StringBuilder is not synchronized.
- A Concatenation operator "+" is internally implemented using either StringBuffer or StringBuilder.
- If the Object value is not going to change use String Class because a String object is immutable.
- If the Object value can change and will only be accessed from a single thread, use a StringBuilder because StringBuilder is unsynchronized.
- If the Object value can change and will be modified by multiple threads, use a StringBuffer because StringBuffer is synchronized.
Advertisements