IntelliJ keep suggesting to replace .length == X
with .lengthCompare(X) == 0
. Why is that better? Don't quite get it, since the suggested changes are more verbose.
It is more efficient.
Since length
is a linear
operation on some collections like List
, doing x.length == 3
would need to compute the length first and then compare it with the value. On the other hand .lengthCompare
would terminate computing the length once it finds that the comparison is wrong already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With