title: How can I convert a string to char[] without copying the object?
body: <p>I have a string and I need to traverse it as a char array.
  Of course the normal method is to use <code>toCharArray()</code></p>
  
  <pre><code>String str = "Hello";
  char[] charArr = str.toCharArray();
  </code></pre>
  
  <p>Now, the source code for toCharArray() is as follows.</p>
  
  <pre><code>public char[] toCharArray() {
      // Cannot use Arrays.copyOf because of class initialization order issues
      char result[] = new char[value.length];
      System.arraycopy(value, 0, result, 0, value.length);
      return result;
  }
  </code></pre>
  
  <p>So Java is creating a new object in memory of type char[] and copying the string object to the new object.</p>
  
  <p>My question is whether or not it is possible to use a string as a char[] without copying the array. My intention is to save on memory space. If this is not possible, is there a reason so? </p>
  
  <p>Thanks in advance!</p>