package cn.itcast_02;
/*
* StrinbBuffer的添加功能:
* public StringBuffer append(String str):可以把任意类型的数据添加到字符串缓冲区里面,并返回字符串缓冲区本身。
* public StringBuffer insert(int offset,String str):在指定位置把任意类型的数据插入到字符串缓冲区里面,并返回字符串缓冲区本身。
*/
public class StringBufferDemo {
public static void main(String[] args) {
// 创建字符串缓冲区对象
StringBuffer sb = new StringBuffer();
// public StringBuffer append(String str):可以把任意类型添加到字符串缓冲区里面。
// StringBuffer sb2 = sb.append("hello");
// System.out.println("sb:" + sb);
// System.out.println("sb2:" + sb2);
// System.out.println(sb == sb2);// true
//一步一步的添加数据
// sb.append("hello");
// sb.append(true);
// sb.append(12.5);
// sb.append(132.45f);
//链式编程
sb.append("hello").append(true).append(12.5).append(123.45f);
System.out.println("sb:"+sb);
System.out.println("-----------------------------");
//public StringBuffer insert(int offset,String str):在指定位置把任意类型的数据插入到字符串缓冲区里面,并返回字符串缓冲区本身。
sb.insert(5, "world");
System.out.println("sb:"+sb);
}
}
常见对象_StringBuffer的添加功能
原创
©著作权归作者所有:来自51CTO博客作者wx62dfdc6aea345的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
docker bridge ip白名单
导读: 参加网易云微专业5个月有余,发现现在自己开始疲惫了,虽然课程进度没落下,但是也没深入学透彻,写博客是为了巩固知识,具体会从微专业第一堂课持续输出.Docker网址: https://docs.docker.com/get-started/这次输出内容为 Docker专题,都是从课堂上总结下来的知识点,自己有XMind的输入,主要分成 docker简介Linux上的Docker安装
docker bridge ip白名单 网易云课堂-微专业Java Docker docker centos