集合判断不用size判断用isEmtpy判断

Sonar静态代码检查发现下面缺陷:

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

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() method can be O(n).

用isEmpty判断的话可以更加有性能上的优势,而且isEmpty返回的是boolean,而size返回的是一个值,更适合于做判断条件

你可能感兴趣的:(集合判断不用size判断用isEmtpy判断)