B4J Question Maps - order of elements

LucaMs

Expert
Licensed User
Longtime User


If: "The order in B4A and B4J maps is preserved."
why: You shouldn't use these methods (GetValueAt and GetKeyAt)?


Also, can I... safely use the class you (Erel) posted here with B4J "thread safe maps"?


Thank you
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
why: You shouldn't use these methods (GetValueAt and GetKeyAt)?
These methods were introduced before the For Each loop was available as a way to iterate over the entries.
There performance can be bad if they are misused.

The correct and simple way to iterate over a Map is with a For Each loop.
Also, can I... safely use the class you (Erel) posted here with B4J "thread safe maps"?
No. Or more correctly only if you add locks in all the methods. In that case you should use a regular Map anyway.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…