当前位置: 技术问答>java相关
急:各位救命!!!!!!!!(一个关于类型转换问题)
来源: 互联网 发布时间:2015-01-08
本文导语: 如何将String转化成StringBuffer类型 | String s1="AA"; StringBuffer sb1=new StringBuffer(s1); StringBuffer public StringBuffer(String str) Constructs a string buffer so that it represents the same sequence of characters as the string argum...
如何将String转化成StringBuffer类型
|
String s1="AA";
StringBuffer sb1=new StringBuffer(s1);
StringBuffer
public StringBuffer(String str)
Constructs a string buffer so that it represents the same sequence of characters as the string argument; in other words, the initial contents of the string buffer is a copy of the argument string. The initial capacity of the string buffer is 16 plus the length of the string argument.
Parameters:
str - the initial contents of the buffer.
StringBuffer sb1=new StringBuffer(s1);
StringBuffer
public StringBuffer(String str)
Constructs a string buffer so that it represents the same sequence of characters as the string argument; in other words, the initial contents of the string buffer is a copy of the argument string. The initial capacity of the string buffer is 16 plus the length of the string argument.
Parameters:
str - the initial contents of the buffer.
|
这样替代一下,应该可以吧?
public class buffer {
public static void main(String args[]) {
String tmp;
tmp="abcde";
int tmp_len=tmp.length();
//buffer设长一些
StringBuffer tmpbuffer = new StringBuffer(tmp_len + (tmp_len/10));
tmpbuffer.append(tmp);
System.out.println(tmpbuffer);
}
}
public class buffer {
public static void main(String args[]) {
String tmp;
tmp="abcde";
int tmp_len=tmp.length();
//buffer设长一些
StringBuffer tmpbuffer = new StringBuffer(tmp_len + (tmp_len/10));
tmpbuffer.append(tmp);
System.out.println(tmpbuffer);
}
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。