当找到一个特殊字符串direcList
时,我将firstDirec
分为两个子列表secondtDirec
和New direction
。
然后我将特定字符串从列表中过滤掉,而不是将它们添加到新的ArrayList
s timeListFirst and timeListSecond
中。一切都适用于firstDirec
,并且元素未添加到timeListFirst
,但我在此位置遇到secondtDirec
列表的问题:
if (!(mergeLine.equals(otherDirection))
因为此位置mergeLine
等于"Ravensbusch"
,所以otherDirection
也是timeListSecond
。尽管如此,这个字符串仍被添加到 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);
}
}
。有人可以解释我的错误吗?
mergeLine值:
otherDirection值:
var
startTime = Date.now();
html = "",
includes = ["header.html","content.html","footer.html"],
filesLoaded = 0,
fileTotal = 3,
fs = require('fs'),
compileFile = function() {
fs.readFile(includes[filesLoaded], 'utf8', function readFileResponse(err, data) {
if(err) {
console.log(err);
} else {
html += data;
filesLoaded++;
if(filesLoaded >= fileTotal) {
writeIndex();
return;
}
compileFile();
}
});
},
writeIndex = function() {
console.log(html);
fs.writeFile('index.html', html, function(err) {
if(err) {
console.log("file not written: " + err);
} else {
console.log("Compiled file in " + String(Date.now() - startTime) + "ms");
}
});
}
compileFile();
答案 0 :(得分:5)
看起来otherDirection
的值在其末尾有一个空格,因此它们不相等,因为那里有!
,整个表达式为true
。