private void removeLettersFromMakeWords(List<String> a, List<String> b){
Iterator<String> i = a.iterator();
for(String s:b)
while (i.hasNext()) {
Object o = i.next();
if(o.toString().equals(s)){
i.remove();
break;
}
}
}
I use an iterator to loop through my list and remove an element from the list if there is a match.
For example: if a = [a, y, f, z, b] and b = [a, f] --> the output will be a = [y, z, b]
Problem is if a = [a, y, f, z, b] and b = [f, a] --> the output will be a = [a, y, z, b]
and the iterator doesn't remove the [a] value in the beginning. Is there a way to reset the iterator so that every time I break the iterator starts from the beginning? Or is there a better way to solve this issue?
a.removeAll(b)instead of all that code.