This is another solution, maybe not be the best or more efficient, but works, and shows the power of this libraries.
So, you can use lambdaj (download here - website) and hamcrest (download here - website), this libraries are very powerfull for managing collections, the following code is very simple and works perfectly:
import static ch.lambdaj.Lambda.having;
import static ch.lambdaj.Lambda.on;
import static ch.lambdaj.Lambda.select;
import static org.hamcrest.Matchers.stringContainsInOrder;
import java.util.Arrays;
import java.util.List;
public class StringContains_03{
public static void main(String[] args) {
List<String> source = Arrays.asList("This time only $FB,$RUG is highest priority".split(" "));
List<String> patterns = Arrays.asList("$FB","$F");
boolean patternsExistsInSource = select(source, having(on(String.class), stringContainsInOrder(patterns))).size()>0;
System.out.println(patternsExistsInSource);//shows: true
System.out.println(select(source, having(on(String.class), stringContainsInOrder(patterns))));//shows the matches: [$FB,$RUG]
}
}
Note that only with this line you know if the pattern is in another.
boolean patternsExistsInSource = select(source, having(on(String.class), stringContainsInOrder(patterns))).size()>0;
With this libraries you can solve your problem in one line. You must add to your project: hamcrest-all-1.3.jar and lambdaj-2.4.jar.
NOTE: This will help you assuming you can have alternatives to your code. I hope this will be useful.
(EDITED) Now works too for the case, "This time only $FB,$RUG is highest priority".