turning a sentence to an array java

Solutions on MaxInterview for turning a sentence to an array java by the best coders in the world

showing results for - "turning a sentence to an array java"
Raphael
21 Jan 2017
1String s = "This is a sample sentence.";
2String[] words = s.split("\\s+");
3for (int i = 0; i < words.length; i++) {
4    // You may want to check for a non-word character before blindly
5    // performing a replacement
6    // It may also be necessary to adjust the character class
7    words[i] = words[i].replaceAll("[^\\w]", "");
8}