It seems to me that calling string.length()
each time takes significantly longer than just accessing a variable.
String
implements interface CharSequence, which in turn defines length
method. You couldn't do the same with variables since variables can't be abstract or overridden.
As other people say, Java is using interfaces heavily.
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