Created
April 15, 2018 23:56
-
-
Save branflake2267/d7f1adae21d419464f3f55f4b6d9bdd1 to your computer and use it in GitHub Desktop.
Dart 101 - The List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() { | |
| [1, 2, 3]; // literal | |
| print([1, 2, 3]); | |
| var list = ['a', 'b', 'c']; | |
| print(list); | |
| var list2 = <String>['a', 'z', 'k']; | |
| print(list2); | |
| List<String> list3 = <String>['aa', 'bb', 'cc']; | |
| print(list3); | |
| var empty = []; | |
| print("is empty $empty"); | |
| empty.add('m'); | |
| empty.add('o'); | |
| empty.add('r'); | |
| print("empty is no $empty"); | |
| var list4 = new List<String>(); | |
| print(list4); | |
| list4.add('a'); | |
| list4.add('d'); | |
| list4.add('d'); | |
| print("list4 is $list4"); | |
| list4.insert(0, 'd'); | |
| print("list4 is now $list4"); | |
| var fixed = new List<String>(3); | |
| print("fixed is $fixed"); | |
| var accessing = ['aa', 'bb', 'cc', 'dd']; | |
| String item = accessing[2]; | |
| print(item); | |
| int end = accessing.length - 1; | |
| String lastItem = accessing[end]; | |
| print("lastItem $lastItem"); | |
| var filling = new List.filled(3, 0); | |
| print("filling is $filling"); | |
| var sorting = ['z', 'i', 'a']; | |
| sorting.sort((String l, String r) { | |
| return l.compareTo(r); | |
| }); | |
| print("sorting is now $sorting"); | |
| sorting.forEach((String value) { | |
| print("v is $value"); | |
| }); | |
| for (String v in sorting) { | |
| print ('vv is $v'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://youtu.be/tGTr3oFlCSg - This code is covered in this youtube video.
https://dartpad.dartlang.org/d7f1adae21d419464f3f55f4b6d9bdd1 - The dart pad for this code.