Answers for "Dart set list spread operator"

1

Dart set list spread operator

/*Dart 2.3 introduced the spread operator (...) and the null-aware spread operator (...?),
which provide a concise way to insert multiple values into a collection.
For example, you can use the spread operator (...) 
to insert all the values of a list into another list:*/
var list = [1, 2, 3];
var list2 = [0, ...list];//var list and values added to list2 wich contains 0 already.
assert(list2.length == 4);

/*If the expression to the right of the spread operator might be null, 
you can avoid exceptions by using a null-aware spread operator (...?):*/
var list;
var list2 = [0, ...?list];
assert(list2.length == 1);
Posted by: Guest on August-16-2021

Code answers related to "Dart set list spread operator"

Code answers related to "Dart"

Browse Popular Code Answers by Language