Collection.isEmpty() should be used to test for emptiness
2017-07-26 17:29
351 查看
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).
Noncompliant Code Example
Compliant Solution
Noncompliant Code Example
// Noncompliant if (myCollection.size() == 0) { /* ... */ }
Compliant Solution
if (myCollection.isEmpty()) { /* ... */ }
相关文章推荐
- SonarQube-Java规范之Atomic-".equals()" should not be used to test the values of "Atomic" classes
- This event supports the .NET Framework infrastructure and is not intended to be used directly from your code?继承自VScrollbar的自定义winform控件,某些事件不触发的问题(Winform控件开发学习)
- The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid
- EF之数据库连接问题The specified named connection is either not found in the configuration, not intended to be used with the Ent
- Why 1904 testing methods should not be used for today’s students
- The specified named connection is either not found in the configuration, not intended to be used
- IOS警告:Property access result unused - getters should not be used for side effects
- centos 6.3 使用 vnc xrdp 远程登陆 不断弹出对话框“ Authentication is required to set the network proxy used for downloading packages ”
- 使用asp.net urlrewrite 出现 Session state can only be used when enableSessionState is set to true 错误
- 45 You want to disable resumable space allocation for all sessions. Which value should be assigned t
- eclipse中如何去除警告:Class is a raw type. References to generic type Class<T> should be parameterized
- jquery crossdomain post plugin i changed bit test code suite for my env,due to the windows env is not familiar with github operation,i didn't forked form the original resposeritoy
- swift 第三方库迁移错误解决“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choo
- The specified named connection is either not found in the configuration, not intended to be used
- jsp 自定义标签 错误 : Unable to compile class for JSP: ,apache cannot be resolved or is not a field
- Proxy account failing to run SSIS Error (Proxy (11) is not allowed for subsystem "SSIS" and user "AB\testuser ".
- vs2005下出现“Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive”的解决方法
- [转载] mysql5.6 删除之前的ibdata1文件后再重新生成,遇到[Warning] Info table is not ready to be used. Table 'mysql.slave_master_info' cannot be opened.问题
- The specified named connection is either not found in the configuration, not intended to be used
- to disable the entity lazy load, The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.