Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a sequence is empty in Kotlin

How to check if a sequence is empty in Kotlin? What's the simplest way?

like image 607
Shreck Ye Avatar asked Dec 14 '22 10:12

Shreck Ye


1 Answers

If you mean literally a Sequence, use none() without arguments for "is empty" and any() for "is not empty".

For other collections, these method names work as well, but there's also isNotEmpty(). Strangely, there is isEmpty, but only for arrays!

like image 138
Alexey Romanov Avatar answered Dec 17 '22 22:12

Alexey Romanov