title: Remove adjacent duplicate characters in a String(java) i.e input:aaaabbbccdbbaae output: abcdbae
body: <p>my code does not give expected output,but dry run works fine.please give a look where is the problem</p>
  
  <pre><code>public static StringBuffer singleOccurence(String s)
  {
   StringBuffer sb = new StringBuffer(s);
   int length=s.length();
  
  
   for(int i=0; i&lt; length ; i++)
   {
    for(int j=i; i&lt;length&amp;&amp;j&lt;length ; j++)
    {
      if(sb.charAt(i)!=sb.charAt(j+1)) 
           i=j+1;
      else
      sb.deleteCharAt(j+1);
     } 
   }
  
   return sb;
  }
  </code></pre>
  
  <p>also gives StringIndexOutOfBounds</p>