I want to create a list (non-GUI) that is searchable (and fast) using something like Get("abc"), but retains its order so I can traverse the list in the same order as the items that were added.
A map would almost work except the order of items added is not retained.
A list would almost work except if I want to look something up, the List.IndexOf looks for the entire entry. In other words, if I want to add a Key and Value then I would need a custom Type for the entry, but then I have to search on the entire custom type (including the value) and since I am trying to get the value, this is not going to work.
Example:
It is almost as if I need to write my own class MapList that uses both a List (to retain the order of the items added) and a Map so I can retrieve the value for a given key.
Is there another solution?
TIA
A map would almost work except the order of items added is not retained.
A list would almost work except if I want to look something up, the List.IndexOf looks for the entire entry. In other words, if I want to add a Key and Value then I would need a custom Type for the entry, but then I have to search on the entire custom type (including the value) and since I am trying to get the value, this is not going to work.
Example:
B4X:
Private Listx as ListMap
ListX.initialize
ListX.Add("A", "Testing 1 2 3")
ListX.Add("X", "abcd")
ListX.Add("B", "bbbb")
if ListX.IndexOf("X") >= 0 then
'Do something
end if
for i=0 to ListX.Size-1
private locValue as String
locValue = ListX.Get(i)
log(locValue)
next
It is almost as if I need to write my own class MapList that uses both a List (to retain the order of the items added) and a Map so I can retrieve the value for a given key.
Is there another solution?
TIA