📜  将句子转换为数组 java 代码示例

📅  最后修改于: 2022-03-11 14:52:27.386000             🧑  作者: Mango

代码示例1
String s = "This is a sample sentence.";
String[] words = s.split("\\s+");
for (int i = 0; i < words.length; i++) {
    // You may want to check for a non-word character before blindly
    // performing a replacement
    // It may also be necessary to adjust the character class
    words[i] = words[i].replaceAll("[^\\w]", "");
}