Possible Duplicate:
In Java, for a string x, what is the runtime cost of s.length()? Is it O(1) or O(n)?
How exactly does the length method of String class work in Java ?
Is it a for loop in linear time or there is a field keeping the track of length so that its constant time ?