Dart Base language – Lists
List is an ordered List
var l = [1.2.3];
print(l);
Copy the code
automatic
List<int> l = new List(a); l .. add(1)
..add(2)
..add(3);
print(l);
Copy the code
Fixed length
List<int> l = new List(3);
// print(l[0]);
l[0] = 1;
l[1] = 2;
l[2] = 3;
print(l);
Copy the code
attribute
| | name that | | — – | — – | | isEmpty whether | null | | isNotEmpty | whether isn’t empty | | first | first object | | last | last object | | length number of | | | Reversed inversion | |
var l = [1.2.3];
print(l.first);
print(l.last);
print(l.length);
print(l.isEmpty);
print(l.isNotEmpty);
print(l.reversed);
Copy the code
methods
| | name that | | — – | — – | | add add | | | addAll | add multiple | | insert insert | | | insertAll | insert multiple | | indexOf query | | | IndexWhere | according to the conditions query | | remove delete | | | removeAt | deleted by location | | fillRange | according to interval filling | | getRange | according to interval for | | shuffle query | | | IndexWhere | random transform order | | sort sort | | | sublist | | create
add
List<int> l = new List(a); l .. add(1)
..addAll([2.3.4.5])
..insert(0.6)
..insertAll(6[6.6]);Copy the code
The query
print(l.indexOf(5));
print(l.indexWhere((it) => it == 4));
Copy the code
delete
l.remove(6);
print(l);
l.removeAt(5);
print(l);
Copy the code
Range
l.fillRange(0.3.9);
print(l.getRange(0.5));
Copy the code
Shuffle the deck
l.shuffle();
print(l);
l.shuffle();
print(l);
Copy the code
The sorting
/ / digital
l.sort();
print(l);
/ / date
List<DateTime> dtList = new List(a); dtList.addAll([DateTime.now(),
DateTime.now().add(new Duration(days: - 12)),
DateTime.now().add(new Duration(days: 2 -)));print(dtList);
dtList.sort((a, b) => a.compareTo(b));
print(dtList);
Copy the code
Copy sublist
print(l);
var l2 = l.sublist(1.4);
print(l2);
Copy the code
The operator
| | name that | | — – | — – | | | + connection | | [] value | | | | = | assignment []
var l1 = [1.2.3];
var l2 = [4.5.6];
print(l1 + l2);
l1[2] = 9;
print(l1[2]);
Copy the code
PDF document sorting:
Dart Basic Language Learning – Part 1. PDF
Blog Source: Blog of rainy Night