Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

are string the same as stringbuffers cos....  RSS feed

 
Tim Tock
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i have a statement that takes a string, but doesnt like taking a stringbuffer, are the two very different, for example, i wanna do
imaString=imaStringBuffer;
so that i can put imaString into a statement:
return_results.updateString(1,imastring);
please help , thanks
 
David Peterson
author
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the toString() method of the StringBuffer, to convert it to a String.
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strings are not the same as StringBuffer, one of the important differences is that Strings objects are immutable, while StringBuffers object are not (mutable).
If your program involves a lot of String concatenation then I suggest you use StringBuffer instead.
You can always convert a StringBuffer to String using the toString() method as David suggested.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!