List.contains in not working

Since so many people have viewed this question, I wanted to provide an updated answer to this for anybody who visits this question in 2018 & beyond: The upcoming version of Salesforce (Spring '18) does add the contains() method to List: Spring '18 Release Notes: New and Changed Classes

contains(listElement)

Returns true if the list contains the specified element.


The List class does not have a contains method. Use the Set class instead:

Set<Id> userIdsToRemove = new Set<Id>();
if (!userIdsToRemove.contains(u.Id)) { /* do stuff */ }

Tags:

List

Apex