This is the relevant piece of my code (false is returned if the whole cycle is finished, pattern is a String passed to the function):
for (FileLine fileLine : fileLines) {
itemText = fileLine.getText();
itemStrings = new ArrayList<String>();
itemStrings.addAll(Arrays.asList((itemText).split(" ")));
for (String itemString : itemStrings) {
if (itemString.equalsIgnoreCase(pattern)) {
return true;
}
}
}
How can I speed this up? I've tried using regex, something like:
//before the for cycle
Pattern regexPattern = Pattern.compile(pattern);
//in the cycle
if (regexPattern.matcher(itemText).matches())
return true;
But it doesn't work for some reason. Maybe I'm doing it wrong, or there's a completely different way of accomplishing this?