Is it O(n) or O(1) (By saving length in a private variable during string allocation to the object).
if it is O(n), does it mean that the complexity of following code is
String internally maintains an array of characters and length of the array is a property of array object hence O(1) as its simple reading of property.