I want to compare if a provided string starts with any of the strings in an array. The easiest solution being:
String b = ...;
boolean matched = false;
for (String a : array) {
if (b.startsWith(a))
match = true;
}
However, intuitively, I want to use something like a trie to get better efficiency since the array of strings might grow to be pretty big and I need to run these matches fast. I can guarantee that these strings are all alphabetical. I can also guarantee that all strings in the array are length 2 or less. What's the best way to implement this trie-like structure in Java? I couldn't find any Java-based libraries that does this.
Thanks!