I have a List
List list = new ArrayList();
list.add(\"ABCD\");
list.add(\"EFGH\");
list.add(\"IJ KL\")
If suggestion from Roadrunner-EX does not suffice then, I believe you are looking for Knuth–Morris–Pratt algorithm.
Time complexity:
So, the complexity of the overall algorithm is O(n + k).
Normal Brute-Force will have time complexity of O(nm)
Moreover KMP algorithm will take same O(k) complexity for searching with same search string, on the other hand, it will be always O(km) for brute force approach.