I am trying to optimize a small class that loops through an array of strings and compares to see if another string equals one of the values, for example:
String test = "this is test5";
String array[] = {"test1","test2","test3, test4,test5,test6,test7,test8"};
for(int i = 0;i < array.length; i++)
{
if (test.endsWith(array))
{
return array[i];
}
}The array that I am using holds closer to 15 values, but this loop can be hit thousands of times a day. My question is, are there any faster ways to loop through multiple strings than using arrays? How do array lists or maps compare?