[Java]
// Connect various types of data through the append () method
/* Public class Append {
Public static void main (String [] args ){
StringBuffer buf = new StringBuffer ();
Buf. append ("Hello \ n ");
Buf. append ("Hello"). append ("World! \ N ");
Buf. append ("number:"). append (1). append ("\ n"); // code chain
Buf. append ("Boolean:"). append (true );
System. out. println (buf );
}
}*/
/* Public class Append {
Public static void main (String [] args ){
StringBuffer buf = new StringBuffer ();
Buf. append ("Hello ");
Fun (buf );
System. out. println (buf );
}
Public static void fun (StringBuffer s ){
S. append ("MLDN"). append ("LiXingHua ");
}
}*/
// Hello MLDN LiXingHua
// Directly use the insert () method to add content to StringBuffer at the specified position
/* Public class Append {
Public static void main (String [] args ){
StringBuffer buf = new StringBuffer ();
Buf. append ("Hello !!! ");
Buf. insert (0, "Hello ");
System. out. println (buf );
Buf. insert (buf. length (), "MLDN ~~ ");
System. out. println (buf );
}
}*/
// String inversion operation -- reverse
/* Public class Append {
Public static void main (String [] args ){
StringBuffer buf = new StringBuffer ();
Buf. append ("World !!! ");
Buf. insert (0, "Hello ");
String str = buf. reverse (). toString ();
System. out. println (str );
}
}*/
// Replace the content in the specified range -- replace
/* Public class Append {
Public static void main (String [] args ){
StringBuffer buf = new StringBuffer ();
Buf. append ("Hello"). append ("World !! ");
Buf. replace (6, 11, "LiXiHua ");
System. out. println (buf );
}
}*/
// String truncation -- substring
/* Public class Append {
Public static void main (String [] args ){
StringBuffer buf = new StringBuffer ();
Buf. append ("Hello"). append ("World !! ");
Buf. replace (6, 11, "LiXiHua ");
String str = buf. substring (6, 15 );
System. out. println (str );
}
}*/
// Delete the string in the specified range -- delete
/* Public class Append {
Public static void main (String [] args ){
StringBuffer buf = new StringBuffer ();
Buf. append ("Hello"). append ("World !! ");
Buf. replace (6, 11, "LiXiHua ");
String str = buf. delete (6, 15). toString ();
System. out. println (str );
}
}*/
// Query whether the specified content exists -- indexOf
Public class Append {
Public static void main (String [] args ){
StringBuffer buf = new StringBuffer ();
Buf. append ("Hello"). append ("World !! ");
If (buf. indexOf ("Hello") =-1 ){
System. out. println ("specified content not found ");
} Else {
System. out. println ("you can find the specified content ");
}
}
}