Uploaded image for project: 'Reference Application'
  1. Reference Application
  2. RA-1801 Search and fix minor errors
  3. RA-1810

Collection.isEmpty() should be used to test for emptiness

    XMLWordPrintable

Details

    • Low

    Description

      SonarQube:

      Using Collection.size() to test for emptiness works, but using Collection.isEmpty() makes the code more readable and can be more performant. The time complexity of any isEmpty() method implementation should be O(1) whereas some implementations of size() can be O( n).

      Problem:
      Using the size() method to determine if the collection is empty.

      Solution:
      Using the isEmpty() method for this purpose.

      Where the problem occurs:

      Support materials:

      Gliffy Diagrams

        Attachments

          Activity

            People

              isamanya Irene Samanya
              sacull Lukasz Debicki
              Daniel Kayiwa Daniel Kayiwa
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 1 hour Original Estimate - 1 hour
                  1h
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 day, 7 hours
                  1d 7h