Getting Started with Java--stringbuffer class Recognize the StringBuffer class
If a string needs to be changed frequently, you need to use the StringBuffer class. (A variable of type string can be difficult to change once it is declared, and if you want to change it, you must change the reference address)!
Connection operation for Strings
Use the Append method in the program book to connect the strings.
Package Sep22;public class StringBufferDemo01 {public static void main (string[] args) {StringBuffer buf=new stringbuffer ( ); Buf.append ("Hello");//use Append to add content buf.append ("world!"). APPEND ("!!!!"); /Continuous Add content buf.append ("\ n"); Buf.append ("Number:"). Append (1). Append ("\ n"); System.out.println (BUF);}}
Hello WORLD!!!!! Numbers: 1
Add content to StringBuffer at any location
You can use the Insert () method directly.
Package Sep22;public class StringBufferDemo03 {public static void main (string[] args) {StringBuffer buf=new stringbuffer ( ); Buf.append ("wodld"); Buf.insert (0, "Hello"); System.out.println (BUF);}}
Hello WODLD
String inversion operation
Getting Started with Java--stringbuffer class