public static void main(String[] args) {
String sentence = "Can you split me please ?";
String[] words = splitStringToStringArray(sentence);
for (String word : words){
System.out.println(word);
}
}
public static String[] splitStringToStringArray(String string) {
StringTokenizer str = new StringTokenizer(string);
String[] result = new String[str.countTokens()];
for(int e=0;str.hasMoreElements();e++) {
result[e] = str.nextToken();
}
return result;
}
Pretty neat ain't it ? Feel free to leave a comment on it.
1 Kommentar:
thx for this enlightening explanation.
Kommentar veröffentlichen