Android Code Snippet [B4X] List to array

B4X compiler automatically casts arrays to lists.
You can use this code in the rare case where you want to convert a list to an array of objects:
B4X:
Public Sub ListToArray(Items As List) As Object()
    #if B4A or B4J
    Return Items.As(JavaObject).RunMethod("toArray", Null)
    #Else
    Dim b(Items.Size) As Object
    For i = 0 To Items.Size - 1
        b(i) = Items.Get(i)
    Next
    #End If
End Sub
 

Daestrum

Expert
Licensed User
Longtime User
I might be wrong, but B4I code path doesn't seem to return anything. (Think a line is missing in your example)
 
Last edited:
Top