I have one list that contains Company objects.
List<Company> companiesList
and every Company has a getName() method that returns company name.
List<Company> companiesList has couple of companies inside and I would like to compare this list with a list of string that contains company names
And this is my comparison list
List<String> searchList = Arrays.asList("abc", "xyz");
I have my method that gets the companies and with stream and filters it with some conditions from DB and I would like to add another filter that returns me the companies which equal to the strings in searchList
So basically the idea is to compare each element in companiesList with getName() and check if that exists in searchList list
public List<Company> getCompanies(String country, List<String> searchList, String version) {
List<Company> result = countriesByCountryCache.getUnchecked(country)
.stream()
.filter(s -> version.compareTo(s.getVersion()) >= 0)
//here to filter like for each element, i want to compare element.getName() and check if it exists in searchList and collect it
.collect(Collectors.toList());
return result;
}
I know it has been asked many times and there are many examples but I couldn't find a proper, correct solution that works. Thanks in advance!