Recursion method in Java
<p>I am trying to use a recursive method to change strings to char arrays but i am getting an error </p>

<pre><code>Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(Unknown Source)
</code></pre>

<p>I want to solve this problem only using recursive method(not loop or toChar method)</p>

<pre><code>public class Recur {
    public char[]  stringTochar(String str)
    {
        if (str != null &amp;&amp; str.length() &gt; 0)
        {
            System.out.println(str.charAt(0)) ;
            stringTochar(str.substring(1)); 
        }
        return stringTochar(str.substring(1)) ;
    }
}

public class Tester {
    public static void main(String[] args) {
        Recur recur= new Recur ();
        recur.stringTochar("this is a test");
    }
}
</code></pre>
