title: Why is String equals not working in my code?
body: <p>I have already checked two compared strings, but even the value parameter str and temp is printed both "mn". The str.equals(temp) is still returning false.</p>
  
  <pre><code>public int strStr(String haystack, String needle) {
              StringBuffer str=new StringBuffer(needle);
  
              int result=-1;
  
              for(int i=0;i&lt;=haystack.length()-needle.length();i++){
                  StringBuffer temp = new StringBuffer(haystack.substring(i, i+needle.length()));
  
                  System.out.println(temp.equals(str));
                  System.out.println(temp+"="+str);
  
                  if (str.equals(temp)){
                      result=i;
                      break;
                  }
              }
              return result;
          }
  </code></pre>