Android 用空格作为分割符切割字符串
2019-11-14 本文已影响0人
哇哇_刘
项目中有需要用到空格作为分割符切割字符串,进而转为List。
String wordStore = edWord.getText().toString();
String[] word = wordStore.split("\\s+");
List<String> wordsList = Arrays.asList(word);
会出现用户在输入的时候不小心多输入了一个、两个甚至多个空格的情况,单用一个“ ”字符来作分割符是不够的,以上方法可以完美解决该情况。