Android Code Snippet Fun With Lists

It doesn't improve anything, but it makes my code more readable. :cool:

B4X:
Sub NewList As List
    Dim newLst As List
    newLst.Initialize
    Return newLst
End Sub

Sub ListHas(data as String, listObj As List)
    Return listObj.IndexOf(data) > -1
End Sub

Sub ListDoesNotHave(data as String, listObj As List)
    Return listObj.IndexOf(data) == -1
End Sub


B4X:
Sub Implementation_Example
    Dim myList = NewList As List
    ...
    ...
    If ListHas(myList, "milk") Then
        ...
    Else If ListDoesNotHave(myList, "eggs") Then
        ...
    End If
End If
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Sometimes, the very few extra code lines that a general usage sub takes up, can gain us many many code lines in the whole program...
We forget to look at the trees while searching for the forest!
 
Top