救命!!!!!!!(再问一下关于类型转换问题)

windygirl 2001-06-14 11:14:00
如何把StringBuffer转换成String
...全文
51 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
asper 2001-06-14
String toString()
Converts to a string representing the data in this string buffer.
回复
StringBuffer sb1="";
String s1=sb1.toString();

toString
public String toString()
Converts to a string representing the data in this string buffer. A new String object is allocated and initialized to contain the character sequence currently represented by this string buffer. This String is then returned. Subsequent changes to the string buffer do not affect the contents of the String.
Implementation advice: This method can be coded so as to create a new String object without allocating new memory to hold a copy of the character sequence. Instead, the string can share the memory used by the string buffer. Any subsequent operation that alters the content or capacity of the string buffer must then make a copy of the internal buffer at that time. This strategy is effective for reducing the amount of memory allocated by a string concatenation operation when it is implemented using a string buffer.

Overrides:
toString in class Object
Returns:
a string representation of the string buffer
回复
windygirl 2001-06-14
回复
beyondii 2001-06-14
同意,呵呵,问这个问题的同志一定没有用一个非常方便的带提示的ide
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-06-14 11:14
社区公告
暂无公告