For Each k As String In Map.Keys
Dim v As Object = Map.Get(k)
...
Next
The only purpose of these methods in B4A was to allow developers to iterate over the Map items
They will not be removed.Ok, but please, do not remove them from B4A
Hash maps are not suitable for this task. It is better to use two maps in this case.But if i need recover a key for some value ?
Sub FindKeyForValue(m As Map, v As Object) As Object
For Each k As Object in m.Keys
If m.Get(k) = v Then Return k
Next
End Sub
Hi, i often use the methods
"Map.GetKeyAt()" and "Map.GetValueAt()"
in my B4A-Programms.
Is it possible to implement these methods in B4I?
Thanks, George
These methods will not be added.
The only purpose of these methods in B4A was to allow developers to iterate over the Map items. This was before the For Each loop was available.
A standard Map structure doesn't support these methods so adding them requires a more complicated (and less optimized) structure.
This code is faster and doesn't require a custom structure under the hood.B4X:For Each k As String In Map.Keys Dim v As Object = Map.Get(k) ... Next
For Each k As String In Map.Keys
Dim v As Object = Map.Get(k)
...
Next
Dim iLoopIndex As Int = 0
Dim iKeyIndex As Int = 5
For Each k As String In mLocalMap.Keys
Dim v As Object = mLocalMap.Get(k)
...
If iLoopIndex = iKeyIndex Then
Exit
End If
iLoopIndex = iLoopIndex + 1
Next