Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove duplicates from an unordered Immutable.List()?

Tags:

How would one remove duplicates from an unordered Immutable.List()? (without using toJS() or toArray())

e.g.

Immutable.List.of("green", "blue","green","black", "blue") 
like image 279
ThorbenA Avatar asked Mar 07 '16 20:03

ThorbenA


People also ask

How do you remove duplicates from a list in flutter?

Try the following: List<String> duplicates = ["a", "c", "a"]; duplicates = duplicates. toSet(). toList();


1 Answers

You can convert it to a Set. A Set is a List with unique values.

Immutable.List.of("green", "blue","green","black", "blue").toSet() 

If you need it as list again just convert it back then:

Immutable.List.of("green", "blue","green","black", "blue").toSet().toList() 

Update:

It exists a shorter possibility to get unique values:

Immutable.List.of("green", "blue","green","black", "blue").distinct 
like image 154
Varon Avatar answered Sep 22 '22 18:09

Varon