【发布时间】:2023-03-03 03:13:01
【问题描述】:
我有一个字符串 - “Hello@World@Good@Morning”
我想在字符串数组中添加替代词。例如,从上面的字符串中,我应该只将 Hello 和 good 添加到我的新数组中。
for (String s : StringsTokens) {
myStringArray = s.split(Pattern.quote("@"));
}
如何只将备用元素添加到字符串数组。
【问题讨论】:
-
你能把你的代码分享为minimal, complete, verifiable example吗?
-
备用元素是具有索引
i的元素,例如:i%2 == 0.... -
使用
for (int i = 0 ; i < SringsTokens.lenght ; i++) { // do your test here : if(i%2 == 0) then add the element to your array