📄 stringbuffermethods.java
字号:
import java.io.*;
public class StringBufferMethods
{
public static void main (String[] args)
{
StringBuffer str = new StringBuffer("This cannot be");
int i, numChars;
System.out.println("The original string is: " + str);
numChars = str.length();
System.out.println(" This string has " + numChars + " characters.");
// insert characters
str.insert(4, " I know");
System.out.println("The string, after insertion, is now: " + str);
numChars = str.length();
System.out.println(" This string has " + numChars + " characters.");
// replace characters
str.replace(12, 18, "to");
System.out.println("The string, after replacement, is: " + str);
numChars = str.length();
System.out.println(" This string has " + numChars + " characters.");
// append characters
str.append(" correct");
System.out.println("The string, after appending, is: " + str);
numChars = str.length();
System.out.println(" This string has " + numChars + " characters.");
// reverse the characters
str.reverse();
System.out.println("The string, after being reversed is: " + str);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -