commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steffen Heil" <li...@steffen-heil.de>
Subject RE: isBlank implementation question for educational purposes, please
Date Fri, 26 Jan 2007 10:03:56 GMT
Hi

> Actually his will be slower even if it's blank.  Strings are 
> immutable (meaning they can't be changed), so under the hood 
> the trim() method will have the overhead of creating a new 
> String object.  Then it will have to cycle through each 
> character in the original String to copy the non-trimmed 
> characters into the new String instance.  So even if it was 
> blank it has the overhead of checking every character just to 
> copy them into the new String that it will return.

No.
substring does not copy Strings.
It just returns new String objects, that refer to the original char[], but
have different offset and length values.

I haven't looked at the implementation right now, but I assume, it justs
counts isSpace(s) from the start and from the end and calls substring.
Therefor it's execution time should be linear to the amount of spaces at the
beginning and end and be independant from the length of the rest of the
String.

Regards,
  Steffen

Mime
View raw message