在Java中使用indexOf

Leg*_*ggy 2 java string

我正在尝试使用indexOf(""); 在这个字符串上

"This i$ an aardvaAr yeEeeAs onDo qwerty XYZ9";

这是我的代码

        space = word.indexOf(" ");

        tempWord = word.substring(0, space);
Run Code Online (Sandbox Code Playgroud)

现在我得到了我想要的This字符串,但是现在我如何得到它之后i$的下一个空格:和下一个单元格结束字符串?

*编辑

请不要这个问题的数组

Jon*_*eet 6

使用其重载indexOf也采用起始索引:

int nextSpace = word.indexOf(" ", space + 1);
Run Code Online (Sandbox Code Playgroud)

(虽然对你的更大问题可能有更好的方法.)