Given a unordered list of List<String>, I need to find whether there exist a String that matches supplied String.
So, i loop
for (String k : keys) {
if (Utils.keysMatch(k, anotherKey)) {
result = true;
break;
}
}
Where Utils.keysMatch checks if appropriate matching can happen.
Can the same be done without a complete iteration? Note that k may be a regular expression.
You can do it in elegant way with Guava’s Iterables.any method and static Predicates class
like this:
return Iterables.any(keys, Predicates.containsPattern(k);