Java: Example - Words to array
//-------------------------------------------------- stringToArray()
// Put all "words" in a string into an array.
String[] stringToArray(String wordString) {
String[] result;
int i = 0; // index into the next empty array element
//--- Declare and create a StringTokenizer
StringTokenizer st;
st = new StringTokenizer(wordString);
//--- Create an array which will hold all the tokens.
result = new String[st.countTokens()];
//--- Loop, getting each of the tokens
while (st.hasMoreTokens()) {
result[i++] = st.nextToken();
}
return result;
}