I need to remove redundant (String) elements from a list. Or perhaps to prevent them from being entered in the first place is the better solution? Sets do not allow duplicates, but they also do not keep order and I need the order. This is a common problem for me so I am looking for a possible language solution for full efficiency.
(In the past I have extended an Array Class to add my own add_unique() method, but this seems like it is a common enough issue to be handled by the language and likely more efficiently.)
Thanks,
_g
Use toset and then toList
var ids = [1, 4, 4, 4, 5, 6, 6];
var distinctIds = ids.toSet().toList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With