Notifications
Announcements
No record found.
Hi,
How to check if list is empty
So if pass null or empty string to the list.. this if condition doesn't work, it still enters the if statement
If (list && list.elements() && list.empty())
How to check for null and empty string?
That's correct. If you create a list and one element (e.g. containing an empty string, for example), the list is not null, elements() returns 1 and empty returns false, because the list isn't empty - it contains one element.
If you want to check values of elements inside the list, you'll need to iterate the list and look at those elements.
For example:
ListEnumerator enumerator = list.getEnumerator(); while (enumerator.moveNext()) { if (!enumerator.current()) { ... } }
Hi Martin,
It doesn't work. If I pass "" or null
If(!enumerator.current()) doesn't work..it enters the if statement in both cases
If it enters the block, it works correctly. The condition says "if the current value is empty". Maybe you overlooked the negation (! operator).
Your question was "How to check for null and empty string?".
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 544 Most Valuable Professional
André Arnaud de Cal... 450 Super User 2025 Season 2
Sohaib Cheema 250 User Group Leader