SHARE
TWEET

Untitled

a guest Oct 21st, 2019 129 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. listCase() {
  2.   // List<dynamic>
  3.   List randomList = [
  4.     "There is a phrase",
  5.     234,
  6.     2.0094,
  7.     ["Another random list", 98, 0x04]
  8.   ];
  9.  
  10.   // List<Object> - In this case, we use String object.
  11.   List<String> names = ["Kennan", "Fattahillah", "Herdyhanto"];
  12.  
  13.   // Nested List - T as a dynamic type.
  14.   List<List<dynamic>> nestedList = [
  15.     ["First Offset"],
  16.     ["Second Offset"]
  17.   ];
  18.  
  19.   // Memory matter and clone.
  20.   List<String> baseList = ["Kennan", "Fattah"];
  21.   List<String> copyList = baseList;
  22.   baseList[0] = "Herdyhanto";
  23.   print(copyList); // [Herdyhanto, Fattah]
  24.  
  25.   List<String> cloneList = [...baseList]; // Clone the baseList
  26.   baseList[0] = "Another";
  27.   print(copyList); // [Another, Fattah]
  28.   print(cloneList); // [Herdyhanto, Fattah]
  29. }
  30.  
  31. setCase() {
  32.   /**
  33.    * CONCLUSION:
  34.    * Set is basically the main collection data type.
  35.    * It can be a HashMap, HashSet (List?).
  36.    *
  37.    * Collection of key.
  38.    *
  39.    * Object in JS ^^.
  40.    * Dictionary in Python.
  41.    */
  42.   // runtimeType: _InternalLinkedHashMap<dynamic, dynamic>
  43.   var mapDynamic = {"something": false, "yeay": 1, 23: "false"};
  44.   // runtimeType: _CompactLinkedHashSet<String>
  45.   var setString = <String>{"A", "B", "C"};
  46.   // runtimeType: _InternalLinkedHashMap<String, int>
  47.   var mapStringInt = <String, int>{"key": 1};
  48.  
  49.   print(mapDynamic);
  50.   print(setString);
  51.   print(mapStringInt);
  52.  
  53.   print(setString.elementAt(0)); // "A"
  54. }
  55.  
  56. mapCase() {
  57.   /**
  58.    * Collection of key.
  59.    *
  60.    * Object in JS ^^.
  61.    * Dictionary in Python.
  62.    */
  63.   // runtimeType: _InternalLinkedHashMap<dynamic, dynamic>
  64.   Map a = {
  65.     "first_val": 1,
  66.     "second_val": false,
  67.     "third_val": [
  68.       {0x01},
  69.       {0x02},
  70.       {0x03}
  71.     ]
  72.   };
  73.   print(a);
  74.   print(a["third_val"][0].elementAt(0)); // _CompactLinkedHashSet<int> -> 1
  75. }
  76.  
  77. main(List<String> args) {
  78.   // listCase();
  79.   // setCase();
  80.   // mapCase();
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top