Android Question IterableList remove item in loop

warwound

Expert
Licensed User
Longtime User
I have a Map with String keys and each value is a List of a custom type.
I'm iterating through the Map keys and values and need to remove keys and List values at some point.
I want to do:

B4X:
Type FileInfo( _
    FileName As String, _
    LastModified As Long _
)

Private FilesMap As Map


B4X:
For Each LocalFolderName As String In FilesMap.Keys
    If blah blah Then
        '    remove map value
        FilesMap.Remove(LocalFolderName)
    End If
Next

or

B4X:
For Each LocalFolderName As String In FilesMap.Keys
    Dim FileInfos As List=FilesMap.Get(LocalFolderName)
    For Each FileInfo1 As FileInfo In FileInfos
        If blah blah Then
            '    remove value from List where List is Map value
            FileInfos.RemoveAt(FileInfos.IndexOf(FileInfo1))
        End If
    Next
Next

Is this likely to cause problems or can the IterableList handle these modifications made within a loop?

Thanks.
 

DonManfred

Expert
Licensed User
Longtime User
I guess it gives problems.
I would create a new list of all items to remove. In the for each filling the items to remove.
After the loop i would remove all the marked items from FileInfos
 
Upvote 0
Top