i would like to sort Uint8list or List lists in flutter
Example in js:
[ Uint8Array.from([1, 2, 3]), Uint8Array.from([0, 1, 2]) ].sort() -> [[0, 1, 2], [1, 2, 3]]
Thx
i would like to sort Uint8list or List lists in flutter
Example in js:
[ Uint8Array.from([1, 2, 3]), Uint8Array.from([0, 1, 2]) ].sort() -> [[0, 1, 2], [1, 2, 3]]
Thx
2
Answers
you can use this mehode:
input:
output:
I’m presuming you want to sort the
List<int>
s in a similar way to lexicographical sorting ofString
s. That is,list1
should precedelist2
iflist1[n] < list2[n]
for somen
and iflist1[i] == list2[i]
for alli < n
. If so, basically write a string comparison function but forint
s:List
first.which prints: