I have a collection of strings, which I only want to search to provide the first few letters.
For example, consider the list of wires: [Tom, Tomas, Ellis, Tolstoy, John] will result in [[Tom, Tom's, Tolstoy] results in string []].
Display is a major issue here and this list can be very large.
What is the best way to optimize it? Index? Sorting? how?
Thanks
is a triangular universal solution, as is already suggested But if you want a light and relatively quick solution without dependency, simply put your string in TreeSet and
tailSet () prefix, then repeat through tail set again until you find a string that is not match It is. (Note: This can also be the first element, if none of your prefix matches the prefix.)
If your list is not larger than two thousand stars, then this method is very much in practice that's good. / P>
Comments
Post a Comment