Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- listCase() {
- // List<dynamic>
- List randomList = [
- "There is a phrase",
- 234,
- 2.0094,
- ["Another random list", 98, 0x04]
- ];
- // List<Object> - In this case, we use String object.
- List<String> names = ["Kennan", "Fattahillah", "Herdyhanto"];
- // Nested List - T as a dynamic type.
- List<List<dynamic>> nestedList = [
- ["First Offset"],
- ["Second Offset"]
- ];
- // Memory matter and clone.
- List<String> baseList = ["Kennan", "Fattah"];
- List<String> copyList = baseList;
- baseList[0] = "Herdyhanto";
- print(copyList); // [Herdyhanto, Fattah]
- List<String> cloneList = [...baseList]; // Clone the baseList
- baseList[0] = "Another";
- print(copyList); // [Another, Fattah]
- print(cloneList); // [Herdyhanto, Fattah]
- }
- setCase() {
- /**
- * CONCLUSION:
- * Set is basically the main collection data type.
- * It can be a HashMap, HashSet (List?).
- *
- * Collection of key.
- *
- * Object in JS ^^.
- * Dictionary in Python.
- */
- // runtimeType: _InternalLinkedHashMap<dynamic, dynamic>
- var mapDynamic = {"something": false, "yeay": 1, 23: "false"};
- // runtimeType: _CompactLinkedHashSet<String>
- var setString = <String>{"A", "B", "C"};
- // runtimeType: _InternalLinkedHashMap<String, int>
- var mapStringInt = <String, int>{"key": 1};
- print(mapDynamic);
- print(setString);
- print(mapStringInt);
- print(setString.elementAt(0)); // "A"
- }
- mapCase() {
- /**
- * Collection of key.
- *
- * Object in JS ^^.
- * Dictionary in Python.
- */
- // runtimeType: _InternalLinkedHashMap<dynamic, dynamic>
- Map a = {
- "first_val": 1,
- "second_val": false,
- "third_val": [
- {0x01},
- {0x02},
- {0x03}
- ]
- };
- print(a);
- print(a["third_val"][0].elementAt(0)); // _CompactLinkedHashSet<int> -> 1
- }
- main(List<String> args) {
- // listCase();
- // setCase();
- // mapCase();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement