commons-lang icon indicating copy to clipboard operation
commons-lang copied to clipboard

Added indexesOf method

Open iashok22 opened this issue 7 years ago • 3 comments

indexesOf () - Finds the indexes of all the occurrences of given search key found in the given string.

iashok22 avatar Oct 05 '17 07:10 iashok22

The question here is whether to use the more grammatically correct "indices" or the more casual "indexes".

garydgregory avatar Jan 12 '18 17:01 garydgregory

I think the method should return an empty collection instead of null

if(isEmpty(source) || searchKey == null ) {  
    return Collections.emptyList();
} 

kedar-joshi avatar Sep 04 '18 18:09 kedar-joshi

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);
    }
}

kedar-joshi avatar Sep 04 '18 18:09 kedar-joshi