3

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

assylias
  • 321,522
  • 82
  • 660
  • 783
Bala
  • 4,427
  • 6
  • 26
  • 29

1 Answers1

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:

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

EDIT:

See this SO answer by Guava's lead dev.

Community
  • 1
  • 1
Grzegorz Rożniecki
  • 27,415
  • 11
  • 90
  • 112