Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个链接列表。一个项目可能位于该列表的多个索引处(例如索引 0、索引 3 和索引 5)。如何查找这些索引之一是否为索引 0;我需要它,因为我使用一些公式来计算一些值,如果项目的一个位置是索引 0,则公式是不同的。
您可以检查第一个元素是您想要的对象
if (list != null && list.size() > 0 && list.get(0).equals(element))
您可以使用get列表上的equals方法和项目上的方法
get
equals
list.get(0).equals(myItem);
通常你不想get(int)在 a上使用,LinkedList因为它是一个 order n 遍历。但索引 0 将始终位于最前面,并且是一个非常短的遍历。:)
get(int)
LinkedList