I have two list:
List<String> firstList = new LinkedList<String>();
List<String> secondList = new LinkedList<String>();
I want to know if every element of a list is contained by the other list. A possible solution could be:
public boolean function(List<String> first, List<String> second)
{
first = firstList;
second = secondList
for (String item : firstList)
{
for (String elem : secondList)
{
if(elem.compareTo(item)!=0)
return false;
}
}
return true;
}
As we can see, the time is quadratic. Is there a way to do it better?