on 04-06-2007 4:46 AM
how to convert StringBuffer to String Array ?
StringBuffer strContent=new StringBuffer();
for(int i=0;i<3;i++){
strContent.append("This is new message:" +i);
}
//how to add to this
String[] strArrContent = {};
Hi Yzme,
we can differentiate between String and String buffer like , A string buffer is similar to String, but the contents can be modified at any point of time using some methods.
To convert a String buffer into a String we have toString() method.
for example :
x = "a" + 4 + "c"
is similar to
x = new StringBuffer().append("a").append(4).append("c")
.toString()
where x is a string..
reference :
<a href="http://java.sun.com/j2se/1.4.2/docs/api/">http://java.sun.com/j2se/1.4.2/docs/api/</a>
Do reward points..if this helps u in reaching at ur solution;
//
how to convert StringBuffer to String Array ?
StringBuffer strContent=new StringBuffer();
for(int i=0;i<3;i++){
strContent.append("This is new message:" +i);
}
//how to add to this
String[] strArrContent = {};
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
String[] strArrContent = new String[]{strContent.toString()};
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Denis,
I think this will result, in a single element array.
If we output strArrContent.length it will give only 1. Is that correct?
What i understood by the requirement is that Yzme wants different messages
in different element of the array like
strArrContent[0] = "This is new message0";
strArrContent[1] = "This is new message1";
strArrContent[2] = "This is new message2";
Yzme, please verify your requirement.
Thanks,
Prashil
Hi Yzme,
Put a seperater in between the strings like &,
<i>strConent.append("This is a new message"i"&");</i>
Now you can split the stringbuffer into an array;
<i>strArrContent[] = strContent.split("&");</i>
This will split the stringbuffer into elements of Array with a seperator as "&";
Regards,
Prashil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.