The `single` property in Dart checks that this iterable has only one element and returns that element.
The syntax of Runes.single property is:
int single
This single property of Runes checks that this iterable has only one element, and returns that element.
Runes.single returns value of type int
.
In this example,
numbers
with one element, the number 5.single
property to retrieve the single element from the list.void main() {
List<int> numbers = [5];
int singleNumber = numbers.single;
print(singleNumber);
}
5
In this example,
characters
with one element, the character 'a'.single
property to retrieve the single element from the list.void main() {
List<String> characters = ['a'];
String singleChar = characters.single;
print(singleChar);
}
a
In this example,
words
with one element, the string 'hello'.single
property to retrieve the single element from the list.void main() {
List<String> words = ['hello'];
String singleWord = words.single;
print(singleWord);
}
hello
In this Dart tutorial, we learned about single property of Runes: the syntax and few working examples with output and detailed explanation for each example.