分享

StringBuffer类的添加功能

 樱花梦_张艺馨 2016-11-01
===============append 练习一====================
package ss1;
/**
 * StringBuffer类的添加功能:
 *
 * public StringBuffer append(boolean b) //追加任意类型数据,返回的是他本身
 * public StringBuffer insert(int offset, boolean b) //插入数据
*/
public class Menu {
 public static void main(String[] args) {
  StringBuffer sb = new StringBuffer();
  StringBuffer sb2 =sb.append("hello");
  System.out.println(sb);
  System.out.println(sb2);
  System.out.println(sb2 == sb );
 }
}
结果:
hello
hello
true
========================append 练习二========================
public class Menu {
 public static void main(String[] args) {
  StringBuffer sb = new StringBuffer();
  sb.append("hello");
  sb.append(true);
  sb.append(12);
  System.out.println(sb);
 }
}
结果:
hellotrue12
=========================append 练习三=====================
public class Menu {
 public static void main(String[] args) {
  StringBuffer sb = new StringBuffer();
  sb.append("hello") .append(true).append(12);
  System.out.println(sb);
 }
}
结果:
hellotrue12
=====================insert  练习四=====================
public class Menu {
 public static void main(String[] args) {
  StringBuffer sb = new StringBuffer();
  sb.append("hello").append(true).append(12);
  System.out.println(sb);
  sb.insert(5, "word");
  System.out.println(sb);
 }
}
结果:
hellotrue12
hellowordtrue12

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多