title: Trouble writing a method that takes a string and returns an array of chars
body: <p>I'm new to Java and stuck on the code below. I don't know how to return the char array; and also if I change the string <code>"purple"</code> to something else, Java won't compile the code.</p>
  
  <pre><code>public class Assigment4 {
  
      public static void main(String[] args) {
          // I get an error if color is initialized with a longer or shorter string.
          String color = "purple"; 
          char[] a = turnStringtoChar(color);
          System.out.println(a);
      }
  
      public static char[] turnStringtoChar(String color) {
          char[] letters = {'p', 'u', 'r', 'p', 'l', 'e'};
  
          for (int i = 0; i &lt; color.length(); i++) {
              // This is the part where I am stuck. I don't know what to return.
              letters[i] = color.charAt(i);
          }
  
          return letters;
      }
  
  }
  </code></pre>
  
  <p>Can anyone help me?</p>