B4J Question List to Array

Blueforcer

Well-Known Member
Licensed User
Longtime User
Is there a simple way to copy the content of a List into a Array?

For now i do it like that. but because this happens every 80ms, i thought there might be a faster/simpler way.

B4X:
Dim bmproot As List

Dim bmp(bmproot.Size) As Int
For index=0 To bmproot.Size-1
    bmp(index)=bmproot.Get(index)
Next
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
i thought there might be a faster/simpler way.
Your code is very simple. The question is whether it is fast enough.

Test it:
B4X:
    Dim bmproot As List
   bmproot.Initialize
   For i = 1 To 100000
       bmproot.Add(Rnd(1, 10000))
   Next
   
   
   Dim n As Long = DateTime.Now
   For Test = 1 To 10000
       Dim bmp(bmproot.Size) As Int
       For index=0 To bmproot.Size-1
           bmp(index)=bmproot.Get(index)
       Next
   Next
   Log((DateTime.Now - n) / 10000)
On my computer it takes 0.1ms to create the array and fill it. Tested with a list of 100k numbers.
This is of course fast enough.
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Youre right. I should messure it before.
But because my List contains maximum 256 Items, the time will be here no longer worth mentioning.
Thnak you!
 
Upvote 0
Top