Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

String using sb.reverse() without new operator

807605Jul 13 2007 — edited Jul 13 2007
Hi, this is a portion of my code:
String sc = Integer.toString(c);
StringBuffer sb = new StringBuffer(sc);
String scr = new String(sb.reverse());
c is a value that a user enters. Now my question is in the last line, it works fine if i type it in the following way:
String scr = new String(sb.reverse());
But if i simply try to use
String scr= sb.reverse();
I get an error saying:
Found java.lang.StringBuffer but expected java.lang.String

As far as i know, String bla = new String("bla"); and String bla = "bla" are the same thing, so why does one work and the other does not?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 10 2007
Added on Jul 13 2007
8 comments
250 views