GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.geeksforgeeks.org — StringBuffer Class in Java - GeeksforGeeks StringBuffer Class in JavaLast Updated : 27 May, 2026 StringBuffer class in Java represents a sequence of characters that can be modified, which means we can change the content of the StringBuffer without creating a new object every time. It represents a mutable sequence of characters.
Example: Here is an example of using StringBuffer to concatenate strings.
Output Hello world Interface Hierarchy Implemented by StringBufferThe diagram shows the interfaces implemented by StringBuffer and illustrates its relationship with Appendable, CharSequence, and Serializable in Java. ![]() Constructors of StringBuffer Class
Example:
Output Default Constructor: Hello With Capacity 50: Java Programming With String: Welcome to Java Implementation of Java StringBuffer Method1. append() Methodappend() method concatenates the given argument with this string.
Output Hello Java 2. insert() Methodinsert() method inserts the given string with this string at the given position.
Output HJavaello 3. replace() Methodreplace() method replaces the given string from the specified beginIndex and endIndex-1.
Output HJavalo 4. delete() Methoddelete() method is used to delete the string from the specified beginIndex to endIndex-1.
Output Hlo 5. reverse() Methodreverse() method of the StringBuffer class reverses the current string.
Output olleH 6. capacity() Methodcapacity() method of the StringBuffer class returns the current capacity of the buffer. The default capacity of the buffer is 16. If the number of characters increases from its current capacity, it increases the capacity by (oldcapacity*2)+2. For example, if the current capacity is 16, it will be (16*2)+2=34.
Output 16 16 34 7. length()This method return the number of character in given string.
Output Length of string GeeksforGeeks=13 Advantages:
Limitations:
StringBuffer all Methods
Comment Explore | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |