码迷,mamicode.com
首页 > 移动开发 > 详细

StringBuffer的insert()方法和append()方法

时间:2015-04-13 09:24:55      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

//StringBuffer的insert()方法和append()方法
class
aa
{
public static void main (String[]
args)
{
StringBuffer str = new
StringBuffer("wlf");
System.out.println(str); //调用insert方法前结果:wlf
str.insert(1,"ang");
System.out.println(str); //调用insert方法后结果:wanglf
System.out.println("---------------------------");
Student
stu = new Student(); //生成自定义类的对象
System.out.println(stu); //我们已经知道,打印对象会自动调用其toString()方法 haha0
//用StringBuffer的append方法添加object,实质为:将object的toString返回值(即String信息)加入StringBuffer尾部
str.append(stu);
System.out.println(str); //wanglfhaha0
}
}
//自定义类
class Student
{
int age; //int型属性默认值为0
public String
toString()
{
return "haha"+age;
}
}

StringBuffer的insert()方法和append()方法

标签:

原文地址:http://www.cnblogs.com/lingyi1111/p/4421280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!