We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I feel dumb, all this time I tought that s.length() was a method that will itarete the String with a complexity of Big(n).
After some research, I found you are right is just a field and accesing is BigO(1).
I apreciate you responded my commends and help me to find the correct answer.
Thank you again.
For other people that had the same idea as me, this is why the field is access by a method:
-[1]"Method is much more flexible in terms of the future of a class. It is almost never done, except in some very early Java classes, to expose a final constant as a field that can have a different value with each instance of the class, rather than as a method."
Tree: Huffman Decoding
You are viewing a single comment's thread. Return to all comments →
Hello Again,
I feel dumb, all this time I tought that s.length() was a method that will itarete the String with a complexity of Big(n). After some research, I found you are right is just a field and accesing is BigO(1). I apreciate you responded my commends and help me to find the correct answer. Thank you again.
For other people that had the same idea as me, this is why the field is access by a method: -[1]"Method is much more flexible in terms of the future of a class. It is almost never done, except in some very early Java classes, to expose a final constant as a field that can have a different value with each instance of the class, rather than as a method."
Reference and more info:
[1]http://stackoverflow.com/questions/8720220/why-is-string-length-a-method