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

windygirl 2001-06-14 11:14:00
如何把StringBuffer转换成String
...全文
82 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
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

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧