I have set of 100000 String. And for example I want to get all strings starting with "JO" from that set. What would be the best solution for that?
I was thinking Aho-Corasick but the implementation I have does not support wild cards.
解决方案
If you want all the strings starting with a sequence you can add all the String into a NavigableSet like TreeSet and get the subSet(text, text+'\uFFFF') will give you all the entries starting with text This lookup is O(log n)
If you want all the Strings with end with a sequence, you can do a similar thing, except you have to reverse the String. In this case a TreeMap from reversed String to forward String would be a better structure.
If you want "x*z" you can do a search with the first set and take a union with the values of the Map.
if you want contains "x", you can use a Navigable> where the key is each String starting from the first, second, third char etc The value is a Set as you can get duplicates. You can do a search like the starts with structure.