anArray.compact()
Removes NULL elements of the array anArray. This is a convenience operation that can be used instead of select from anArray where element.exists();.
anArray
select from anArray where element.exists();
set compactArray = anArray.compact();