Is there any way to check if a list contains a certain element? I looked at the List functions and did not see any contain() function like Java or C# , so I was wondering how other people are handling this.
I really need to use a List I cant use a Map like in this example here
What I have now is really bad..
for (String s : allContacts)
{
for(String ic:insertedContacts)
{
if (s != ic )
{
errorContacts.add(s);
break;
}
break;
}
}
A Set might be what you're looking for.
Set<String> mySet = new Set<String>();
Set.addAll()
method to add all of the List elements to the set. mySet.addAll(myList);
.Set.contains()
method to check the Set for the element you're looking for.