java - Efficient way to test if a string is substring of any in a list of strings -
i want know best way compare string list of strings. here code have in mind, it's clear it's not in terms of time complexity.
for (string large : list1) { (string small : list2) { if (large.contains(small)) { // } else { // not me } } // further manipulation of string }
both lists of strings can contain more thousand values, worst case complexity can rise 1000×1000×length mess. want know best way perform task of comparing string list of strings, in given scenario above.
you this:
(string small : list2) { if (set1.contains(small)) { // } else { // not me } }
set1 should larger list of string, , instead of keeping list<string>
, use set<string>
or hashset<string>
Comments
Post a Comment