Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
This article also participated in the “Digitalstar Project” to win a creative gift package and creative incentive money.
📝 [Flutter] learning to form a record, [programmer essential knowledge]
📔 — Dart data type list&Map!
1. Write at the front
The string in Dart’s base data type was introduced in the previous article, so let’s move on to learning about arrays (list) and dictionaries (Map) in Dart’s base syntax.
The Apple Mac is configured with the Flutter development environment
Android Studio installs a third-party simulator for Flutter — netease MuMu
Failed to find Build Tools Revision 29.0.2
Android license status unknown. Run ‘Flutter doctor — Android – Licenses’
How to create a Flutter project and run your first Flutter project
Dart uses var, final, and const
Dart Indicates the num of the data type
Dart String of data type
This is an array of books.
Dart lists, which are the equivalent of arrays in OC, are mutable and immutable.
2.1 the variable list
Without further ado, directly on the code, as follows:
void main(a){
listTest();
}
void listTest(a){
// Create a list directly
List a = ["1".2."3.0".4.0];
print(a);
/ / var
var list = [1.2."zjp".3.0];
print(list);
}
Copy the code
- The default values are variable, and you can add different data types to the list, which is very convenient.
2.1.1 Obtaining the specified subscript data
// Get the specified subscript data directly
print(list[3]);
// Modify the specified subscript data directly
list[3] = "reno";
Copy the code
2.1.2 Method of Inserting data
/ / insert
list.insert(1."hellow");//list.insert(index, element)
Copy the code
2.1.3 Deleting Data
/ / delete
list.remove(1);
print(list);
Copy the code
2.1.4 Method of clearing data
list.clear();
Copy the code
- The test results are as follows:
2.1.5 Sorting method
Dart is annotated in the same way that you can view a class on iOS: Command + mouse click.
2.2 Immutable List
- immutable
list
I just add it out frontconst
Here it is:
If we add const to the list, it is immutable. We cannot modify the data in the list or we will get an error.
3. Map
3.1 variable Map
In DART, a map is a key-value pair, which is the same as a dictionary in OC.
- Create a Map
void mapTest(a){
Map a = {"a":1."b":2};
print(a);
var a1 = {"a1":1."a2":2};
print(a1);
}
Copy the code
- The running results are as follows:
3.1.1 Map Value and Changed Value
print(a["a"]);/ / value
a["a"] = "aa";/ / value
print(a["a"]);
Copy the code
3.1.2 map length
/ / the length of the map
print(a.length);
Copy the code
3.1.3 Map All keys
// Get all keys
print(a.keys);
Copy the code
3.1.4 Map All values
// Get all values
print(a.values);
Copy the code
- The test results are as follows:
3.2 Map cannot be changed
An immutable map cannot modify key/value pairs as a list does.
- A list can be converted into a map
print(b.asMap());/ / the list to the map
Copy the code
- The results are as follows:
More methods can be found in specific classes.
4. Write in the back
Follow me, more content continues to output
- CSDN
- The Denver nuggets
- Jane’s book
🌹 if you like, give it a thumbs up 👍🌹
🌹 feel harvest, can come to a wave of collection + attention, so as not to find you next time I 😁🌹
🌹 welcome everyone to leave a message exchange, criticism and correction, forwarding please indicate the source, thank you for your support! 🌹