Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Kotlin check if Collection is neither null nor empty

$
0
0

Right now, I am using the following function to do this check

if(list.isNullOrEmpty().not()) {  doSomething()} else {  dont()}

To me, I feel there would be a shorter method to achieve the same like neitherNullNorEmpty() or just isNotEmpty() (current isNotEmpty takes non-nullable list). Something along the lines of CollectionUtils.isNotEmpty(list) which looks cleaner. Right now either I have to add not() at the end or "!", which doesn't look right as I feel there should be a single function to do this. Such a function will make the code more concise and easier to read. Am I missing something or Kotlin is?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>