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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to