番石榴有空吗? [重复]

时间:2022-11-10 20:46:09

This question already has an answer here:

这个问题在这里已有答案:

Is there any equivalent in google Guava for apache commons' CollectionUtils.isEmpty(list) to check if a collection is null or empty?

谷歌Guava中是否有任何等效的apache commons的CollectionUtils.isEmpty(列表)来检查集合是否为空或空?

1 个解决方案

#1


5  

To check if Collection is both null and empty, you must do null check by yourself. Guava devs advocate not to use nulls for Collections at all - see IdeaGraveyard on Guava Wiki:

要检查Collection是否为空和空,您必须自己进行空检查。 Guava开发人员主张不对集合使用空值 - 请参阅Guava Wiki上的IdeaGraveyard:

Prefer to return empty collections instead of null. Then a plain isEmpty check will suffice.

更喜欢返回空集合而不是null。然后一个简单的isEmpty检查就足够了。

EDIT:

编辑:

See this SO answer by Guava's lead dev.

请参阅Guava的主要开发人员的回答。

#1


5  

To check if Collection is both null and empty, you must do null check by yourself. Guava devs advocate not to use nulls for Collections at all - see IdeaGraveyard on Guava Wiki:

要检查Collection是否为空和空,您必须自己进行空检查。 Guava开发人员主张不对集合使用空值 - 请参阅Guava Wiki上的IdeaGraveyard:

Prefer to return empty collections instead of null. Then a plain isEmpty check will suffice.

更喜欢返回空集合而不是null。然后一个简单的isEmpty检查就足够了。

EDIT:

编辑:

See this SO answer by Guava's lead dev.

请参阅Guava的主要开发人员的回答。