B4J Question Group data in a list

stevel05

Expert
Licensed User
Longtime User
It took me a while to understand what you are asking, but I think I've got it. Try using a Map something like:

B4X:
    Dim L As List
    L.Initialize
    Dim M As Map
    M.Initialize
    
    'Create the data
    Dim i As Int
    For i = 0 To 100
        L.Add(Rnd(0,5))
    Next
    
    'Store each value as a map key with it's value maintaining a count of how many times the
    'value has been stored
    For Each Val As Int In L
        M.Put(Val,M.GetDefault(Val,0)+1)
    Next
    
    
    'Add the maps keys to a list so it can be sorted
    Dim L1 As List
    L1.Initialize
    For Each K As Int In  M.Keys
        L1.Add(K)
    Next
    
    'Sort the list
    L1.Sort(True)
    
    
    'Report the item (Key) and how many times it was stored.
    For Each K As Int In L1
        Log(K & " : " & M.Get(K))
    Next
 
Upvote 0

Johan Hormaza

Well-Known Member
Licensed User
Longtime User
It took me a while to understand what you are asking, but I think I've got it. Try using a Map something like:

B4X:
    Dim L As List
    L.Initialize
    Dim M As Map
    M.Initialize
   
    'Create the data
    Dim i As Int
    For i = 0 To 100
        L.Add(Rnd(0,5))
    Next
   
    'Store each value as a map key with it's value maintaining a count of how many times the
    'value has been stored
    For Each Val As Int In L
        M.Put(Val,M.GetDefault(Val,0)+1)
    Next
   
   
    'Add the maps keys to a list so it can be sorted
    Dim L1 As List
    L1.Initialize
    For Each K As Int In  M.Keys
        L1.Add(K)
    Next
   
    'Sort the list
    L1.Sort(True)
   
   
    'Report the item (Key) and how many times it was stored.
    For Each K As Int In L1
        Log(K & " : " & M.Get(K))
    Next
My brother, THANKS!
Thank you so much!
 
Upvote 0
Top