This question already has answers here:
How to get the last value of an ArrayList

(19个回答)


去年关闭。





我正在尝试获取ArrayList中最后添加的项目,以将其与我要添加到它的下一个项目进行比较。如果它们相等,请继续。喜欢:

if (stringArray.get(stringArray.IndexOfLastItemAdded()) == compareLastItemToThis) {
    continue;
}
else {
    stringArray.add(compareLastItemToThis);
}


我知道IndexOfLastItemAdded不存在,但是有类似的东西吗?

最佳答案

stringArray.get(stringArray.size() - 1) ;

应该给你字符串数组列表中的最后一项

关于java - 如何获取ArrayList <String>中的最后一项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22977272/

10-09 05:51