Logo

Programming-Idioms

History of Idiom 118 > diff from v49 to v50

Edit summary for version 50 by programming-idioms.org:
[Dart] DemoURL, code, comments

Version 49

2020-10-11, 00:00:04

Version 50

2020-11-05, 15:12:55

Idiom #118 List to set

Create set y from list x.
x may contain duplicates. y is unordered and has no repeated values.

Idiom #118 List to set

Create set y from list x.
x may contain duplicates. y is unordered and has no repeated values.

Variables
y,x
Variables
y,x
Code
void main() {
  List<int> list = [1,2,3,4,5];
  list.toSet(); 
  print(list);
}
Code
var y = x.toSet();
Comments bubble
List<T> has a method to convert directly to Set<T>.
Comments bubble
List<T> has a method to convert directly to Set<T>.
Doc URL
https://api.dart.dev/stable/2.4.0/dart-core/Set-class.html
Doc URL
https://api.dart.dev/stable/2.4.0/dart-core/Set-class.html
Demo URL
https://dartpad.dev/6c647bf2dc2cc2e7bb5516e08fa7330c