how to optimize the following:
final String[] longStringArray = {"1","2","3".....,"9999999"};
String searchingFor = "9999998"
for(String s : longStringArray)
{
if(searchingFor.equals(s))
{
}
}
NOTE : longStringArray is checked only once during runtime and is not sorted and changes every time I run the program.
I am sure there is a way to improve the worst case performance here, but I cannot find it ...
PS I would also appreciate a solution in which the string searchFor does not exist in the longStringArray array.
Thank.
source
share