- Trending Categories
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
Difference between String class and StringBuffer class 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
- Java StringBuffer class.
- Difference between string and StringBuffer in Java.
- Difference between String and StringBuffer.
- Constructors of StringBuffer class in Java.
- Methods of StringBuffer class in Java.
- Difference between Object and Class in Java
- Difference Between Class and Interface in Java
- What is the difference between Component class and Container class in Java?
- Difference between Abstract Class and Interface in Java
- Difference between Scanner and BufferReader Class in Java
- Difference between StringBuilder and StringBuffer in Java
- What is the difference between abstract class and a concrete class in Java?
- Difference Between Thread Class and Runnable Interface in Java
- Difference Between Interface and Abstract Class in Java & C#

Advertisements