Java如何将字符串插入StringBuffer?
package org.nhooo.example.lang;
public class StringBufferInsert {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer("kodeava");
System.out.println("Text before = " + sb.toString());
//“e”字母。还有其他的重载版本|k|o|d|e|a|v|a|...。
//“e”字母。还有其他的重载版本0|1|2|3|4|5|6|7|...
//
//“e”字母。还有其他的重载版本从上面的序列中,您可以看到
//“e”字母。还有其他的重载版本字符串从0开始,所以当我们在
//“e”字母。还有其他的重载版本第四个偏移量,表示它将在
//“e”字母。还有其他的重载版本"e" letter. There are other overload version of this
//“e”字母。还有其他的重载版本method that can be used to insert other type of data such
//“e”字母。还有其他的重载版本as char, int, long, float, double, Object, etc.
sb.insert(4, "j");
System.out.println("After first insert = " + sb.toString());
//“e”字母。还有其他的重载版本Here we insert a string to the StringBuffer at index 8
sb.insert(8, " examples");
System.out.println("Final result = " + sb.toString());
}
}该程序将打印以下输出:
Text before = kodeava After first insert = nhooo Final result = nhooo examples