I have a list of keywords in a list, and I have data coming from some source, which will also be a list.
I would like to find if any of the keywords in the data list exists, if so add these keywords to another target list.
eg.
Keyword List = FIRSTNAME, LASTNAME, CURRENCY & FUND
Data list = HUSBANDFIRSTNAME, HUSBANDLASTNAME, WIFEFIRSTNAME, SOURCECURRENCY & CURRENCYRATE.
From the above example, I would like to make a target list with keywords FIRSTNAME, LASTNAME & CURRENCY, but FUNDshould not appear because it does not exist in the data list.
I have a solution below that works using two loops (one inside the other) and checking with the String method contains, but I would like to avoid two loops, especially inside inside.
for (int i=0; i<dataList.size();i++) {
for (int j=0; j<keywordsList.size();j++) {
if (dataList.get(i).contains(keywordsList.get(j))) {
targetSet.add(keywordsList.get(j));
break;
}
}
}
Is there any other alternative solution to my problem?