 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of StringBuffer class can anyone explain with an example?
The java.lang.StringBuffer class is a thread-safe, mutable sequence of characters. Following are the important points about StringBuffer −
- 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
import java.lang.*; public class StringBufferDemo {    public static void main(String[] args) {       StringBuffer buff = new StringBuffer("tutorials ");       System.out.println("buffer = " + buff);       // appends the string argument to the string buffer       buff.append("point");       // print the string buffer after appending       System.out.println("After append = " + buff);       buff = new StringBuffer("1234 ");       System.out.println("buffer = " + buff);       // appends the string argument to the string buffer       buff.append("!#$%");       // print the string buffer after appending       System.out.println("After append = " + buff);    } }  Output
buffer = tutorials After append = tutorials point buffer = 1234 After append = 1234 !#$%
Advertisements
 