I have a Arraylist of strings. I want to remove the strings that are substring of another string in that array. I have a python implementation but with java is tricky. Python
def filterSublist(lst):
uniq = lst
for elem in lst:
uniq = [x for x in uniq if (x == elem) or (x not in elem)]
return uniq
For java, I need to check if the element is contained in another element, if yes, then nothing, if not adding it to another one.
for(String element : list){
for(int j = 0; j < list.size(); j++)
if (! element.contains(list.get(j))){
listUniq.add(date);}
}
The java solution doesn't work as it should. one reason is that it also compares element to the element itself. Any help is appreciated.
x == elempart of python.