Android Question Compare MAP Contents

marconotsopolo

Member
Licensed User
Good morning

How do I compare the content of two maps which will both contain an ID and a date. I wish to extract the ID and value if they differ.

example:
Map 1 - 501,2020-07-20 19:21:27.2498612, 536,2020-07-20 19:21:46.2499061, 8000,2020-07-22 20:48:29.7426884, 8001,2020-07-23 07:05:01.451
Map 2 - 501,2020-07-20 19:21:27.2498612, 536,2020-07-20 19:21:46.2499061, 8000,2020-07-22 20:48:29.7426884, 8001,2020-07-23 09:44:59.148

I have tried to use map.containskey by looping through the values as below, but not having much success

B4X:
dim t as int = 0
For Each k As String In bMap.Values
    Dim v As String = bMap.Get(k)                           
        If aMap.ContainsKey(v) Then
             'this is the same key
             'Log("Same key found")
              Log(v)
        Else
              t=t+1
              Log("Different key: " & k & "-" & v)           
        End If
Next

Any help as usual would be appreciated.

Cheers
Mark
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
For Each Key1 As String in Map1.Keys
Dim Value1 As String = Map1.Get(Key1) 'why store date as string???
Dim KeyValueSame As Boolean = False
If Map2.ContainsKey(Key1) Then
  Dim Value2 As String = Map2.Get(Key1)
If Value1 = Value2 Then KeyValueSame = True
'Or if you want to look more sophisticated:
KeyValueSame = Value1 = Value2
End If
If KeyValueSame = False Then
  Log($"Key: ${Key} is different"$)
End If
Next
 
Last edited:
Upvote 0
Top