title: java string-manipulations
body: <p>Ok, so I tried with your help to learn a little bit more about strings and Chaining Strings in Java. </p>
  
  <p>now I know that strings are  immutable, but I'm having a really hard time to do this ex:</p>
  
  <blockquote>
    <p>Implement the method</p>
  
  <pre><code>public static String notReplace(String str)
  </code></pre>
    
    <p>The method takes a String as its input
    and returns a String in which every
    occurrence of the lowercase word "is"
    has been replaced with "is not". The
    word "is" should not 2 be immediately
    preceded or followed by a letter -- so
    for example the "is" in "this"  should
    not be replaced. (Note:
    <code>Character.isLetter(char)</code> tests if a
    char is a letter.)</p>
  </blockquote>
  
  <p><strong>Examples:</strong><br>
  notReplace("is test") → "is not test"<br>
  notReplace("is-is wise") → "is not-is not wise"</p>
  
  <p>This is what I wrote:</p>
  
  <pre><code>public class NotReplace{
  
      public static void main(final String[] args){
          final String str2 = "is no";
          System.out.println(notReplace(str2));
  
      }
  
      public static String notReplace(final String str){
          final int times = str.length();
  
          final StringBuilder sb = new StringBuilder(str);
          for(int i = 0; i &lt;= times; i++){
              if((str.charAt(i) == 'i') &amp;&amp; (str.charAt(i + 1) == 's')
                  &amp;&amp; !Character.isLetter(str.charAt(i + 2))){
                  sb.insert(i, "not");
  
              }
              final String str1 = sb.toString();
              return str1;
  
          }
      }
  }
  </code></pre>
  
  <p>I believe it is a complete mess, I'll be happy to learn more how to work with strings in situations like this.</p>
  
  <p>Thanks</p>
  
  <p>Edit: I can't use replaceAll function.</p>