[ 
http://issues.apache.org/jira/browse/LANG-269?page=comments#action_12419930 ] 

Scott Johnson commented on LANG-269:
------------------------------------

Thank you, Michael.

The indexOfDifference(String[]) method initially scans the String array for the 
shortest String and uses that in the comparisons.  So I don't think there is a 
performance issue with the scenario where there are a bunch of long strings 
with a final short string.  In fact, the algorithm should be pretty efficient 
because it'll compare only few characters of the long strings.

But your idea of comparing the first character in each string then the second, 
third, etc, is more efficient in some scenarios.  For example, if there are a 
large number of long, similar strings with a few very different strings mixed 
in.  This algorithm will reduce the number of comparisons in that case.

When I get some time this afternoon, I'll give that a try.

Thanks for the suggestion.

Scott



> Shouldn't Commons Lang's StringUtils have a "common" string method?
> -------------------------------------------------------------------
>
>          Key: LANG-269
>          URL: http://issues.apache.org/jira/browse/LANG-269
>      Project: Commons Lang
>         Type: New Feature

>  Environment: generic
>     Reporter: Michael Dang
>      Fix For: 3.0
>  Attachments: StringUtils.patch
>
> A method which accepts a string array and returns a string which is the 
> common portion of all the strings starting from the left, or more general 
> form of that.
> This is very common operation.  For example, one may want to find the common 
> directory of a set of path strings.
> passing in:
> "/foo/f1.txt"
> "/foo/moo/f2.txt"
> "/foo/moo/f3.txt"
> should returns "/foo/"
> It is tedious to implement this in every project.  And I think Commons Lang 
> StringUtils should have some methods to help in this.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to