Skip to content

Added indexesOf method#294

Open
iashok22 wants to merge 12 commits intoapache:masterfrom
iashok22:master
Open

Added indexesOf method#294
iashok22 wants to merge 12 commits intoapache:masterfrom
iashok22:master

Conversation

@iashok22
Copy link
Copy Markdown

@iashok22 iashok22 commented Oct 5, 2017

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

return null;
}
return null;
}
Copy link
Copy Markdown
Contributor

@aaabramov aaabramov Oct 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix the formatting, please?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha-ha,They refused to merge only two lines of code modification

@garydgregory
Copy link
Copy Markdown
Member

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

@kedar-joshi
Copy link
Copy Markdown

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

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

@kedar-joshi
Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants