title: JAVA Optimize char[] to String conversion
body: <p>This is a solution to this <a href="https://www.hackerrank.com/challenges/beautiful-binary-string" rel="nofollow noreferrer">Hackerrank Question</a></p>
  
  <pre><code>String b = new String(in.nextLine());
  char[] bCharArray = b.toCharArray();
  for (int i = 0; i &lt; n - 2; i++) {
    if (b.substring(i, i + 3).matches("010")) {
      bCharArray[i + 2] = '1';
      b = new String(bCharArray);
      counter++;
    }
  }
  </code></pre>
  
  <p>Now in the for loop part, each time a new instance for the String b is created. Is there any better way to implement an optimized char[] to String conversion?</p>