You need to sign in to do that
Don't have an account?
waylonatcim
Check if a list contains an object
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 has, so I was wondering how other people are handling this.
Thanks
List doesn't support contains(), this method is only available for Sets and Maps (here its containsKey() actually).
Please note that you can only use primitive types in sets and as key in maps.
So one solution for objects would be to use a map with the object id as key, for example
Hope this helps,
Andreas
Message Edited by wintamute on 11-18-2008 08:41 PM
http://success.salesforce.com/ideaView?c=09a30000000D9xtAAC&id=08730000000b9RZAAY
private static final Set<String> validCountries = new Set<String>(new String[] {'Germany', 'India', 'Japan', 'United States'});
if (validCountries.contains(countryName)) {
// Do your Logic
}
Have a look here (https://developer.salesforce.com/docs/atlas.en-us.212.0.apexcode.meta/apexcode/apex_methods_system_list.htm#apex_System_List_contains).