Dart Runes toList()
Syntax & Examples
Runes.toList() method
The `toList` method in Dart creates a List containing the elements of the Iterable.
Syntax of Runes.toList()
The syntax of Runes.toList() method is:
List<int> toList({bool growable: true })
This toList() method of Runes creates a List containing the elements of this Iterable.
Parameters
Parameter | Optional/Required | Description |
---|---|---|
growable | optional | A boolean value indicating whether the list is growable or not. Defaults to true if not provided. |
Return Type
Runes.toList() returns value of type List<int>
.
✐ Examples
1 Convert runes to list
In this example,
- We create a sequence of Unicode code points
runes
from the string 'Hello'. - We use the
toList
method to convert the runes into a List of integers. - We then print the resulting list to standard output.
Dart Program
void main() {
Runes runes = Runes('Hello');
List<int> runeList = runes.toList();
print('Rune list: $runeList');
}
Output
Rune list: [72, 101, 108, 108, 111]
2 Convert numbers to list
In this example,
- We create a sequence of Unicode code points
numbers
from the string '12345'. - We use the
toList
method to convert the numbers into a List of integers. - We then print the resulting list to standard output.
Dart Program
void main() {
Runes numbers = Runes('12345');
List<int> numberList = numbers.toList();
print('Number list: $numberList');
}
Output
Number list: [49, 50, 51, 52, 53]
Summary
In this Dart tutorial, we learned about toList() method of Runes: the syntax and few working examples with output and detailed explanation for each example.