集册 Java实例教程 通过插入将值添加到StringBuffer

通过插入将值添加到StringBuffer

欢马劈雪     最近更新时间:2020-01-02 10:19:05

550
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
通过插入将值添加到StringBuffer


public class Main {

 /**来 自 时代Java - nowjava.com**/

  public static void main(String[] args) {

    boolean b = true;

    StringBuffer sb1 =  new StringBuffer("Hello  World");

    sb1.insert(6,b);

    System.out.println(sb1);

 

    char c = 'Y';

    StringBuffer sb2 =  new StringBuffer("Hello  World");

    sb2.insert(6,c);

    System.out.println(sb2);

 

    char[] c1 = new char[] {'Y','e','s'};/** 来 自 时 代 J a v a 公 众 号**/

    StringBuffer sb3 =  new StringBuffer("Hello  World");

    sb3.insert(6,c1);

    System.out.println(sb3);

 

    double d = 12.0;

    StringBuffer sb4 =  new StringBuffer("Hello  World");

    sb4.insert(6,d);

    System.out.println(sb4);

 

    float f = 12.0f;

    StringBuffer sb5 =  new StringBuffer("Hello  World");

    sb5.insert(6,f);

    System.out.println(sb5);

 

    int i = 51;

    StringBuffer sb6 =  new StringBuffer("Hello  World");

    sb6.insert(6,i);

    System.out.println(sb6);

 

    long l = 110;

    StringBuffer sb7 =  new StringBuffer("Hello  World");

    sb7.insert(6,l);

    System.out.println(sb7);

   

    Object obj = new String("My ttt");

    StringBuffer sb8 =  
展开阅读全文