我正在将我direcList分成两个子列表firstDirec,secondtDirec当New direction发现一个特殊的字符串时.
然后我通过不将它们添加到新的ArrayLists 来过滤列表中的特定字符串timeListFirst and timeListSecond.一切正常firstDirec,并且元素没有添加到timeListFirst,但我secondtDirec在这个位置的列表面临问题:
if (!(mergeLine.equals(otherDirection))
Run Code Online (Sandbox Code Playgroud)
因为在这个位置mergeLine等于"Ravensbusch",所以是 otherDirection.尽管如此,这个字符串正被添加到timeListSecond.有人可以解释我的错误吗?
mergeLine值:

otherDirection值:

for (String keyLine : direcList) {
if (keyLine.startsWith("New direction")) {
int index = direcList.indexOf(keyLine);
// direcArray.remove(index);
List<String> firstDirec = direcList.subList(0, index);
List<String> secondtDirec = direcList.subList(index,
direcList.size() - 1); // This part wih New
// Direction.
ArrayList<String> timeListFirst = new ArrayList<String>();
for (String mergeLine : firstDirec) {
if (!(mergeLine.equals(direction))
&& !(mergeLine.equals(route))
&& !(mergeLine.equals(day))) {
timeListFirst.add(mergeLine);
}
}
ArrayList<String> timeListSecond = new ArrayList<String>();
for (String mergeLine : secondtDirec) {
if (!(mergeLine.equals(otherDirection))
&& !(mergeLine.equals(route))
&& !(mergeLine.equals(day))
&& !(mergeLine.equals("New direction"))) {
timeListSecond.add(mergeLine);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51 次 |
| 最近记录: |