StringBuffer class
suggest changeKey Points :-
- used to create a mutable (modifiable) string.
- Mutable :- Which can be changed.
- is thread-safe: its methods are synchronized, so concurrent use is safe.
Methods :-
- public synchronized StringBuffer append(String s)
- public synchronized StringBuffer insert(int offset, String s)
- public synchronized StringBuffer replace(int startIndex, int endIndex, String str)
- public synchronized StringBuffer delete(int startIndex, int endIndex)
- public synchronized StringBuffer reverse()
- public synchronized int capacity()
- public synchronized void ensureCapacity(int minimumCapacity)
- public synchronized char charAt(int index)
- public synchronized int length()
- public synchronized String substring(int beginIndex)
- public synchronized String substring(int beginIndex, int endIndex)
Example showing the difference between String and StringBuffer :-
class Test {
public static void main(String args[])
{
String str = "study";
str.concat("tonight");
System.out.println(str); // Output: study
StringBuffer strB = new StringBuffer("study");
strB.append("tonight");
System.out.println(strB); // Output: studytonight
}
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents