string - Substring Recursion from text file Java -


so program use recursion. have import text file containing 5 words , words have find possible substrings , store them in array list. so, if word cards: cards card car ca c ards ard ar rds rd r ds d s.

the instructions must create static method returns arraylist of type string takes single parameter, string.

so in order recursive, must call in order simplify things, , there must action base case. have:

public static arraylist<string> substringcalculator (string thename) {    /* call create new arraylist here? wouldn't mean     * every time call method entire new arraylist     * created? want 1 arraylist.     */    arraylist<string> result = new arraylist<string>();    system.out.print (thestring);    result.add(thestring)   // add string arraylist    if (thestring.length > 1) {       // make new string 1 char less original.       string newstring = thestring.substring(0, thestring.length() - 1);       // call method again new string.       substringcalculator (newstring);       return result;    }    return thestring;   // return string if of length 1. } 

i know not right, i'm not sure how go doing this. help?

here sketch. if string empty, return list containing empty string. if not, have 2 strings: first (the first character in string) , rest of string. find substrings of rest of string, each of these, put first character in possible positions.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -