[SalesForce] Null value check in case of Set

I am using a

set < string > queue = new set < string > ();

I am using an if to filter out null values

if(queue.size() > 0 && !queue.isEmpty())

{ system.debug('queue '+queueaddress); }

In logs I can see that queue is {null}
But still it is going inside the if condition .
Please advise how to do a null check here

Thanks in advance

Best Answer

The only way it will go inside if condition is when your Set has null as a value inside it.

The only way to avoid it to remove it via queue.remove(null); or iterate and skip the null value from Set Or best is to not add null to set.

Related Topic