【发布时间】:2014-05-23 12:34:55
【问题描述】:
我正在尝试获取 ArrayList 中最后添加的项目,以将其与我将要添加的下一个项目进行比较。如果相等,继续。喜欢:
if (stringArray.get(stringArray.IndexOfLastItemAdded()) == compareLastItemToThis) {
continue;
}
else {
stringArray.add(compareLastItemToThis);
}
我知道IndexOfLastItemAdded 不存在,但有类似的吗?
【问题讨论】:
-
另请注意,您不能使用
==运算符比较字符串。而是使用equals( compareListItemToThis )。