Kuinka muutan Stringin StringBufferiksi?
String merkkijono=Oma.lueInt;
StringBuffer uusi = ?????
String merkkijono=Oma.lueInt;
StringBuffer uusi = ?????
Turvaa tilisi vahvistamalla puhelinnumerosi. Voit silloin palauttaa unohtuneen salasanan tekstiviestillä.
Näihin keskusteluihin ei ole vielä vastattu. Ole ensimmäinen.
Vastaukset 4
Vanhimmat
buffer uusi=temp
näin ainakin onnistuu...
Stringbuffer muuttuja = new Stringbuffer();
ja sitten vaan teet jotain esim:
public String nimi(){
muuttuja.append("reijo");
return toString(muuttuja);
}
saatta olla jotain virheitä mut noin se menee!
/**
* 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.
*
* @param str the initial contents of the buffer.
* @exception NullPointerException if str is null
*/
public StringBuffer(String str) {
this(str.length() 16);
append(str);
}
Näin:
String juttua="jotain juttua";
StringBuffer buff = new StringBuffer(juttua);