commons-lang
commons-lang copied to clipboard
Added indexesOf method
indexesOf () - Finds the indexes of all the occurrences of given search key found in the given string.
The question here is whether to use the more grammatically correct "indices" or the more casual "indexes".
I think the method should return an empty collection instead of null
if(isEmpty(source) || searchKey == null ) {
return Collections.emptyList();
}
Also, length of the source
can be cached for better performance e.g.
for (int i = 0, length = source.length(); i < length; i++)
{
if (searchKey.equals(source.charAt(i)))
{
indexList.add(i);
}
}