An empty list is a container of `list` type that has no content. It can be more generally defined as having a length equal to zero.
An empty list is a container of list
type that has no content.
list
can cover many types, depending on the language: Python's list
, Java's List
interface, Caml's List
, C++'s std::list
, etc. For more details, see list.
Most if not all languages implementing a list
type also provide a length
function, that measures the length of a list, thus accepting the concept of "length". Therefore, the most general definition of "having no content" would be:
Has no content, a list whose length is zero.
Programmatically speaking, a list can be checked empty by many different ways, depending on the language's implementation. Here are some examples of functions returning a truthy value if the input list is empty.
Python
def is_empty(l):
return l == []
def is_empty(l):
return not bool(l)
def is_empty(l):
return len(l) == 0
Java
boolean isEmpty(List<E> list) {
return list.isEmpty();
}