假设我有一组字符串:
Set<String> things = new HashSet<String>();
things.add("coffee cup");
things.add("smartphone");
things.add("inkjet printer");
// :
// list could be quite large (100K or so, perhaps loaded from a database)
// :
现在我想检查另一个字符串是否完全包含上述集合中的任何字符串。所以:
"a coffee cup" - matches
"android smartphone" - matches
"inkjet printer for sale" - matches
"laser printer" - does not match
"printer" - does not match
我能想到的唯一方法是遍历集合(如果找到则中断)。有没有更有效和优雅的方法来做到这一点?