I wrote the following code:
for (Character currentChar : userDocuments.keySet()) {
List<QueryDocumentSnapshot> currentList = userDocuments.get(currentChar);
if (currentList == null) {
userDocuments.remove(currentChar);
continue;
}
for (int index = 0; index < currentList.size(); ++index) {
final String currentFullName = currentList.get(index).getString("full_name");
if (currentFullName == null || !(searchText.contains(currentFullName))) {
currentList.remove(index);
}
}
if (currentList.size() == 0) {
userDocuments.remove(currentChar);
}
}
I want to iterate over a map Map<Character,List<QueryDocumentSnapshot>>
check if the full_name (field of each QueryDocumentSnapshot
) contains searchText
and if it's not, remove this element from the list. In case list is empty, remove the entire list. But for some reason I get java.util.ConcurrentModificationException
on the first line. Also, how can I use contains
without case sensitive?