package com.test.part04;
import java.util.*;
public class stringBuilderDemo {
public static void main(String[] args) {
StringBuilder hi=new StringBuilder("Hi");
hi.append("!");//插入字符
hi.append("I am ChaCha!");
System.out.println(hi);
System.out.println(hi.length());
hi.delete(4,7);
System.out.println(hi);
Scanner scan = new Scanner(System.in);
System.out.println("请输入需要插入的字符!");
String in=scan.nextLine();//必须进行类型转换
scan.close();
//插入到stringBuilder中
hi.insert(4,in);
System.out.println(hi);
//将可变字符构建器转换为字符串
String hi01= hi.toString();
String hi02=hi.substring(5,8);//截取需要的部分转换
System.out.println(hi01+hi02);
}
}