cch*_*hua 2 java string sentence
我怎么可以把类似的句子"He and his brother playing football."成几部分一样"He and","and his","his brother","brother playing"和"playing football".是否可以通过使用Java来实现?
假设"单词"总是由单个空格分隔.使用String.split()
String[] words = "He and his brother playing football.".split("\\s+");
for (int i = 0, l = words.length; i + 1 < l; i++)
System.out.println(words[i] + " " + words[i + 1]);
Run Code Online (Sandbox Code Playgroud)