stringbuffer
时间: 2023-09-08 13:10:27 浏览: 59
StringBuffer
StringBuffer is a mutable sequence of characters that can be modified without creating a new object. It is a thread-safe class, which means that multiple threads can access the same instance of StringBuffer without any problem.
The StringBuffer class is similar to the String class, but it provides methods to modify the contents of the string. For example, you can append characters to a StringBuffer, insert characters at a specific position, delete characters, and more.
Here is an example of using StringBuffer:
```
StringBuffer sb = new StringBuffer("Hello");
sb.append(" world!");
System.out.println(sb.toString()); // "Hello world!"
```
In this example, we create a StringBuffer with the initial value "Hello". We then use the `append` method to add the string " world!" to the end of the buffer. Finally, we use the `toString` method to convert the StringBuffer to a regular String and print it. The output is "Hello world!".
阅读全文