Android Question Using IndexOf in a list of arrays

Sathish VM

Member
Licensed User
Longtime User
Hi,

I'm using DBUtils.ExecuteMemoryTable to read a table. This results in a list of arrays, each object being a string array. Now I've to find the indexof a particular string in this list. My code below doesn't work because I figure strings are pointers. Is there any easy way to recode to ensure intEntryFound holds 10?

Dim strStock() as String

lstAllStockList = DBUtils.ExecuteMemoryTable(sqlLocalFile,strQuery,Null,0)
strStock = lstAllStockList.Get(10)
intEntryFound = lstAllStockList.IndexOf(strStock(0))


I've many lists that are read from different tables and I've to use indexOf to identify the location of particular records. I'm hoping that we can make this logic work.

I would like to avoid using select queries on these many tables since these selects would be inside a loop and then there will be a large number of db queries. I am assuming indexOf in a list would be faster and more efficient than a select query, when the code is in a loop.

Thanks,
Sathish
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your code should work. You just need to understand that the array content is not relevant in this case. It will look for the same array instance.

This means that if you have two different arrays with the same values:
B4X:
Dim a() As String = Array As String("1")
Dim b() As String = Array As String("1")
These arrays are two different instances. If you add 'a' to a List then List.IndexOf(b) will return -1.
 
Upvote 0

Sathish VM

Member
Licensed User
Longtime User
Your code should work. You just need to understand that the array content is not relevant in this case. It will look for the same array instance.

This means that if you have two different arrays with the same values:
B4X:
Dim a() As String = Array As String("1")
Dim b() As String = Array As String("1")
These arrays are two different instances. If you add 'a' to a List then List.IndexOf(b) will return -1.

Hi Erel,

thanks for your answer. I've recoded my logic to avoid this indexof since what I really intended to do, was to find the indexOf the array content. And it appears there is no easy way to do that.

Thanks,
Sathish
 
Upvote 0
Top