- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Difference between string and StringBuffer in Java.
Strings, which are widely used in Java programming, are a sequence of characters. In Java programming language, strings are treated as objects. The Java platform provides the String class to create and manipulate strings.
Whereas, StringBuffer class is a thread-safe, mutable sequence of characters.
- A string buffer is like a String, but can be modified.
- It contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
- They are safe for use by multiple threads.
- Every string buffer has a capacity.
Example
public class Sample { public static void main(String args[]) { String str = new String("Hi welcome to tutorialspoint"); System.out.println(str);StringBuffer sBuffer = new StringBuffer("test"); sBuffer.append(" String Buffer"); System.out.println(sBuffer); } }
Output
Hi welcome to tutorialspoint test String Buffer
- Related Articles
- Difference Between String and StringBuffer Class in Java
- Difference between String class and StringBuffer class in Java
- Difference between String and StringBuffer.
- Difference between StringBuilder and StringBuffer in Java
- What is the difference between String, StringBuffer and StringBuilder classes in Java explain briefly?
- What is the difference between a String object and a StringBuffer object in java?
- What is the difference between StringBuffer and StringBuilder in java?
- Differences between String and StringBuffer
- Difference between StringBuffer and StringBuilder.
- What is the difference between a StringBuffer and StringBuilder in java?
- Java String, StringBuffer and StringBuilder Tutorial.
- Sorting collection of String and StringBuffer in Java
- Difference between String buffer and String builder in Java
- Difference between String and Character array in Java.
- How can we replace specific part of String and StringBuffer in Java?

Advertisements