Android Question ContainsKey and EqualsIngnoreCase

schimanski

Well-Known Member
Licensed User
Is it possibel to combine Map.ContainsKey with EqualsIgnoreCase in order to check, if the key exists with another case or do I have to check each key himself in a loop?

B4X:
Dim exists As Boolean=False
For Each key As String In Map1.Keys
  If key.EqualsIgnoreCase(Name)=True Then
     exists=True
     Exit
  End If
Next
If exists Then Log("Exists")
 
Last edited:

stevel05

Expert
Licensed User
The key is of type Object, so you cannot use String methods on it directly.

I am assuming that you are not expecting there to be different cased versions of the same key otherwise your test may find the wrong match, so you could force the keys to all be the same case when you put them in the Map in the first place.
 
Upvote 0
Top