isNotEmpty
IsNotEmpty is a common predicate in programming that indicates whether a container, sequence, string, or collection contains at least one element. It generally evaluates to true when the length, size, or number of elements is greater than zero, and to false when that measure is zero. In languages with strict null handling, the concept may also involve whether a null input is allowed or treated as empty.
Language-specific usage varies:
- Kotlin: isNotEmpty is an extension method on CharSequence and on collections. For example, list.isNotEmpty() is true
- Java: Libraries such as Apache Commons provide StringUtils.isNotEmpty(str) and CollectionUtils.isNotEmpty(coll), which typically return false if the
- Python: There is no universal isNotEmpty function in the standard library. The common pattern is to
- JavaScript: Not built into the language as a single function; practice commonly checks lengths and counts,
Common use cases include input validation, filtering collections, and control flow that should execute only when