8 Replies Latest reply: Jul 13, 2007 10:42 AM by 807605 RSS

    String using sb.reverse() without new operator

    807605
      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?