add method addIfNotNull

This commit is contained in:
2024-12-13 10:56:46 -06:00
parent edec6d64e3
commit 21a5c98376
2 changed files with 33 additions and 0 deletions

View File

@ -700,4 +700,16 @@ public class CollectionUtils
return (map.containsKey(key) && map.get(key) != null);
}
/***************************************************************************
** add an element to a collection, but, only if the element isn't null
***************************************************************************/
public static <T, E extends T> void addIfNotNull(Collection<T> c, E element)
{
if(element != null)
{
c.add(element);
}
}
}