Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html#substring%28int%29" rel="noreferrer"><code>substring</code></a> is indeed a valid method - but it returns a <code>String</code> reference, not a <code>StringBuilder</code>, so you can't assign the return value to <code>sb1</code>. This should work:</p> <pre><code>String x = sb.append("ing").append("a").substring(0); </code></pre> <p>However, you should <em>also</em> take a step back, and look at the error message again. Make sure you understand every part of it, and ask yourself why that wasn't enough information to diagnose the issue yourself. This sort of self-evaluation should help you diagnose future problems without consulting the community. (I'm sure many people are happy to help, but it's more efficient for everyone if you can work it out yourself.)</p> <p>One helpful technique here is to reduce the scope of the issue as far as possible - so I'd probably have isolated it to a single method call first:</p> <pre><code>sb.append("ing").append("a"); sb1 = sb.substring(0); </code></pre> <p>At that point, when the second line flags up an error, there's less to consider. The error would be something like:</p> <pre><code>Test.java:11: error: incompatible types     sb1 = sb.substring(0);                       ^   required: StringBuilder   found:    String 1 error </code></pre> <p>Now admittedly that's not the clearest error message in the world, but given that there is <em>no</em> other use of <code>String</code> in that statement, it <em>has</em> to be the return value of the method - whose documentation you should also check as a matter of course, too.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload