Table of Contents
# first Method
List.first
void main() {
var lst = new List();
lst.add(5);
lst.add(10);
print("The first element of the list is: ${lst.first}");
}
=> output
The first element of the list is: 5
# isEmpty Method
List.isEmpty
void main() {
var lst = new List();
lst.add(5);
lst.add(10);
print(lst.isEmpty);
}
=> output
False
# isNotEmpty Method
List.isNotEmpty
void main() {
var lst = new List();
lst.add(5);
lst.add(10);
print(lst.isNotEmpty);
}
=> output
true
# length Method
List.length
void main() {
var lst = new List();
lst.add(5);
lst.add(10);
print("The length of the list is : ${lst.length}");
}
=> output
The length of the list is : 2
# last Method
List.last
void main() {
var lst = new List();
lst.add(5);
lst.add(10);
print("The last element of the list is: ${lst.last}");
}
=> output
The last element of the list is: 10
# reversed Method
List.reversed
void main() {
var lst = new List();
lst.add(5);
lst.add(10);
print("The list values in reverse order: ${lst.reversed}");
}
=> output
The list values in reverse order: (10, 5)
# single Method
List.single
void main() {
var lst = new List();
lst.add(5);
print("The list has only one element: ${lst.single}");
}
It will produce the following output −
The list has only one element: 5