Android Question Get elements of one array which are not present in another

Hi friends,
As I said in the title, I need to get elements of an array which are not in another.

example:
arr1 = {2, 3, 4}
arr2 = {1, 2, 3, 4, 5}
output = {1, 5}

thanks for help.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The question is not 100% clear but maybe this example will help you:
B4X:
Sub AppStart (Args() As String)
    Dim set1 As B4XSet = B4XCollections.CreateSet2(Array(2, 3, 4, 7))    
    Dim set2 As B4XSet = B4XCollections.CreateSet2(Array(1, 2, 3, 4, 5))
    Dim x As B4XSet = Xor(set1, set2)
    Log(x.AsList)
End Sub

Private Sub Xor(set1 As B4XSet, set2 As B4XSet) As B4XSet
    Dim res As B4XSet
    res.Initialize
    For Each o As Object In set1.AsList
        If set2.Contains(o) = False Then res.Add(o)
    Next
    For Each o As Object In set2.AsList
        If set1.Contains(o) = False Then res.Add(o)
    Next
    Return res
End Sub
 
Upvote 2
Top