├── .gitignore ├── CHANGELOG.md ├── README.md ├── analysis_options.yaml ├── bin ├── belajar_dart_collection.dart ├── check_method.dart ├── comparable.dart ├── comparator.dart ├── convert_method.dart ├── double_linked_queue.dart ├── filter_method.dart ├── hash_map.dart ├── hash_set.dart ├── iterable_properties.dart ├── iterator.dart ├── linked_hash_map.dart ├── linked_hash_set.dart ├── linked_list.dart ├── list_fix.dart ├── list_growable.dart ├── list_method.dart ├── list_operator.dart ├── map.dart ├── map_entry.dart ├── queue.dart ├── set_method.dart ├── splay_tree_map.dart ├── splay_tree_set.dart ├── stack.dart ├── transform_method.dart ├── unmodifiable_list.dart ├── unmodifiable_map.dart └── unmodifiable_set.dart ├── pubspec.lock └── pubspec.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | # Files and directories created by pub. 2 | .dart_tool/ 3 | .packages 4 | 5 | # Conventional directory for build output. 6 | build/ 7 | .idea -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | - Initial version. 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A simple command-line application. 2 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:lints/recommended.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | # linter: 19 | # rules: 20 | # - camel_case_types 21 | 22 | # analyzer: 23 | # exclude: 24 | # - path/to/excluded/files/** 25 | 26 | # For more information about the core and recommended set of lints, see 27 | # https://dart.dev/go/core-lints 28 | 29 | # For additional information about configuring this file, see 30 | # https://dart.dev/guides/language/analysis-options 31 | -------------------------------------------------------------------------------- /bin/belajar_dart_collection.dart: -------------------------------------------------------------------------------- 1 | void main(List arguments) { 2 | print('Hello world!'); 3 | } 4 | -------------------------------------------------------------------------------- /bin/check_method.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | final numbers = [2,4,6,8,10]; 4 | 5 | print(numbers.any((element) => element > 5)); 6 | 7 | print(numbers.every((element) => element > 5)); 8 | 9 | print(numbers.contains(3)); 10 | 11 | } -------------------------------------------------------------------------------- /bin/comparable.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | class Category implements Comparable{ 4 | String id; 5 | String name; 6 | 7 | Category(this.id, this.name); 8 | 9 | @override 10 | int compareTo(Category other) { 11 | return id.compareTo(other.id); 12 | } 13 | 14 | @override 15 | String toString() { 16 | return "Category{id: $id, name: $name}"; 17 | } 18 | } 19 | 20 | void main(){ 21 | 22 | final treeSet = SplayTreeSet(); 23 | // final treeSet = SplayTreeSet((a, b) => b.compareTo(a)); 24 | treeSet.add(Category('3', 'Category 3')); 25 | treeSet.add(Category('1', 'Category 1')); 26 | treeSet.add(Category('2', 'Category 2')); 27 | 28 | print(treeSet); 29 | 30 | } -------------------------------------------------------------------------------- /bin/comparator.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | final treeSet = SplayTreeSet((a, b) => b.compareTo(a)); 5 | 6 | treeSet.addAll([1,3,5,7,9,2,4,6,8]); 7 | 8 | print(treeSet); 9 | } -------------------------------------------------------------------------------- /bin/convert_method.dart: -------------------------------------------------------------------------------- 1 | void main() { 2 | final numbers = [1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 8, 9, 20]; 3 | 4 | final numberSet = numbers.toSet(); 5 | 6 | final numberList = numberSet.toList(growable: true); 7 | numberList.add(10); 8 | 9 | print(numbers); 10 | print(numberSet); 11 | print(numberList); 12 | } 13 | -------------------------------------------------------------------------------- /bin/double_linked_queue.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | 5 | final queue = DoubleLinkedQueue(); 6 | 7 | queue.addLast("Eko"); 8 | queue.addLast("Kurniawan"); 9 | queue.addLast("Khannedy"); 10 | 11 | print(queue.removeFirst()); 12 | print(queue.removeFirst()); 13 | print(queue.removeFirst()); 14 | 15 | print(queue); 16 | 17 | } -------------------------------------------------------------------------------- /bin/filter_method.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | final numbers = [1,2,3,4,5,6,7,8,9,10]; 4 | 5 | print(numbers.firstWhere((element) => element % 3 == 0)); 6 | print(numbers.lastWhere((element) => element % 3 == 0)); 7 | print(numbers.singleWhere((element) => element % 7 == 0)); 8 | 9 | print(numbers.skip(4)); 10 | print(numbers.take(4)); 11 | 12 | final names = ["Eko", "Budi", "Aja", "Joko", "Sari"]; 13 | 14 | print(names.skipWhile((value) => value.length < 4)); 15 | print(names.takeWhile((value) => value.length < 4)); 16 | 17 | print(names.where((element) => element.length < 4)); 18 | print(names.where((element) => element.length > 3)); 19 | 20 | } -------------------------------------------------------------------------------- /bin/hash_map.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | 5 | final scores = HashMap(); 6 | 7 | scores["Eko"] = 100; 8 | scores["Budi"] = 100; 9 | scores["Joko"] = 100; 10 | scores["Dimas"] = 100; 11 | scores["Donis"] = 100; 12 | scores["Hendra"] = 100; 13 | scores["Andi"] = 100; 14 | 15 | print(scores); 16 | 17 | } -------------------------------------------------------------------------------- /bin/hash_set.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | 5 | final set = HashSet(); 6 | 7 | set..add("Eko")..add('Budi')..add("Kurniawan")..add("Khannedy"); 8 | 9 | print(set); 10 | } -------------------------------------------------------------------------------- /bin/iterable_properties.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | final numbers = [1,2,3,4,5,6,7,8,9,10]; 4 | 5 | print(numbers.length); 6 | print(numbers.first); 7 | print(numbers.last); 8 | print(numbers.isEmpty); 9 | print(numbers.isNotEmpty); 10 | // print(numbers.single); 11 | 12 | } -------------------------------------------------------------------------------- /bin/iterator.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | final names = ["Eko", "Kurniawan", "Khannedy"]; 3 | 4 | for (var name in names) { 5 | print(name); 6 | } 7 | 8 | final iterator = names.iterator; 9 | 10 | while (iterator.moveNext()) { 11 | print(iterator.current); 12 | } 13 | } -------------------------------------------------------------------------------- /bin/linked_hash_map.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | 5 | // final scores = Map(); 6 | final scores = LinkedHashMap(); 7 | 8 | scores["Eko"] = 100; 9 | scores["Budi"] = 100; 10 | scores["Joko"] = 100; 11 | scores["Dimas"] = 100; 12 | scores["Donis"] = 100; 13 | scores["Hendra"] = 100; 14 | scores["Andi"] = 100; 15 | 16 | print(scores); 17 | 18 | } -------------------------------------------------------------------------------- /bin/linked_hash_set.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | 5 | // final set = {}; 6 | final set = LinkedHashSet(); 7 | 8 | set..add("Eko")..add('Budi')..add("Kurniawan")..add("Khannedy"); 9 | 10 | print(set); 11 | } -------------------------------------------------------------------------------- /bin/linked_list.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | class StringEntry extends LinkedListEntry{ 4 | String value; 5 | 6 | StringEntry(this.value); 7 | } 8 | 9 | void main() { 10 | 11 | final linkedList = LinkedList(); 12 | 13 | linkedList.add(StringEntry("Eko")); 14 | linkedList.add(StringEntry("Kurniawan")); 15 | linkedList.add(StringEntry("Khannedy")); 16 | 17 | for (var entry in linkedList) { 18 | print(entry.value); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /bin/list_fix.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | final list = List.filled(10, 0); 3 | 4 | // list.add(100); ERROR 5 | 6 | print(list); 7 | 8 | list[0] = 1; 9 | list[1] = 2312; 10 | list[2] = 2312; 11 | 12 | print(list); 13 | } -------------------------------------------------------------------------------- /bin/list_growable.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | final list = []; 3 | 4 | print(list); 5 | 6 | list.add(1); 7 | list.add(2); 8 | list.add(3); 9 | 10 | print(list); 11 | } -------------------------------------------------------------------------------- /bin/list_method.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | final names = ["Eko", "Khannedy"]; 4 | 5 | print(names); 6 | 7 | names.insert(1, "Kurniawan"); 8 | 9 | print(names); 10 | 11 | } -------------------------------------------------------------------------------- /bin/list_operator.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | final names = ["Eko", "Kurniawan", "KHannedy"]; 4 | final authors = ["Programmer", "Zaman", "Now"]; 5 | 6 | final combine = names + authors; 7 | 8 | print(names); 9 | print(authors); 10 | print(combine); 11 | 12 | } -------------------------------------------------------------------------------- /bin/map.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | final Map person = { 4 | "firstName" : "Eko", 5 | "lastName" : "Khannedy" 6 | }; 7 | 8 | print(person); 9 | print(person["firstName"]); 10 | 11 | person["middleName"] = "Kurniawan"; 12 | print(person); 13 | 14 | 15 | } -------------------------------------------------------------------------------- /bin/map_entry.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | final Map person = { 4 | "firstName" : "Eko", 5 | "lastName" : "Khannedy" 6 | }; 7 | 8 | for(var entry in person.entries){ 9 | print('${entry.key} : ${entry.value}'); 10 | } 11 | 12 | } -------------------------------------------------------------------------------- /bin/queue.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | 5 | final queue = Queue(); 6 | 7 | queue.addLast("Eko"); 8 | queue.addLast("Kurniawan"); 9 | queue.addLast("Khannedy"); 10 | 11 | print(queue.removeFirst()); 12 | print(queue.removeFirst()); 13 | print(queue.removeFirst()); 14 | 15 | print(queue); 16 | 17 | } -------------------------------------------------------------------------------- /bin/set_method.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | final names1 = {"Eko", "Kurniawan", "Khannedy"}; 4 | final names2 = {"Budi", "Kurniawan", "Nugraha"}; 5 | 6 | print(names1.union(names2)); 7 | print(names1.intersection(names2)); 8 | print(names1.difference(names2)); 9 | print(names2.difference(names1)); 10 | 11 | } -------------------------------------------------------------------------------- /bin/splay_tree_map.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | 5 | final scores = SplayTreeMap((a, b) => b.compareTo(a)); 6 | 7 | scores["Eko"] = 100; 8 | scores["Budi"] = 100; 9 | scores["Joko"] = 100; 10 | scores["Dimas"] = 100; 11 | scores["Donis"] = 100; 12 | scores["Hendra"] = 100; 13 | scores["Andi"] = 100; 14 | 15 | print(scores); 16 | 17 | } -------------------------------------------------------------------------------- /bin/splay_tree_set.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | 5 | final treeSet = SplayTreeSet(); 6 | 7 | treeSet.addAll([1,3,5,7,9,2,4,6,8]); 8 | 9 | print(treeSet); 10 | 11 | } -------------------------------------------------------------------------------- /bin/stack.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | final queue = Queue(); 5 | 6 | queue.addLast("Eko"); 7 | queue.addLast("Kurniawan"); 8 | queue.addLast("Khannedy"); 9 | 10 | print(queue.removeLast()); 11 | print(queue.removeLast()); 12 | print(queue.removeLast()); 13 | 14 | print(queue); 15 | 16 | } -------------------------------------------------------------------------------- /bin/transform_method.dart: -------------------------------------------------------------------------------- 1 | void main(){ 2 | 3 | final numbers = [1,2,3,4,5,6,7,8,9,10]; 4 | 5 | print(numbers.map((e) => e * 2)); 6 | print(numbers.join(", ")); 7 | 8 | print(numbers.expand((element) => [element, element, element])); 9 | 10 | print(numbers.reduce((value, element) => value + element)); 11 | 12 | // reduce(1, 2) => 3; 13 | // reduce(3, 3) => 6; 14 | // reduce(6, 4) => 10; 15 | 16 | print(numbers.fold("", (value, element) => "$value, $element")); 17 | 18 | } -------------------------------------------------------------------------------- /bin/unmodifiable_list.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | final numbers = [1,2,3,4,5]; 5 | final unmodifiableNumbers = UnmodifiableListView(numbers); 6 | 7 | unmodifiableNumbers.add(100); // error 8 | } -------------------------------------------------------------------------------- /bin/unmodifiable_map.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main(){ 4 | 5 | final Map person = { 6 | "firstName" : "Eko", 7 | "lastName" : "Khannedy" 8 | }; 9 | 10 | final finalPerson = UnmodifiableMapView(person); 11 | 12 | print(finalPerson); 13 | 14 | // finalPerson['middleName'] = 'Kurniawan'; ERROR 15 | 16 | } -------------------------------------------------------------------------------- /bin/unmodifiable_set.dart: -------------------------------------------------------------------------------- 1 | import 'dart:collection'; 2 | 3 | void main() { 4 | final set = {1, 2, 3, 4, 5, 6, 7, 8, 9}; 5 | final unmodifiableSet = UnmodifiableSetView(set); 6 | 7 | unmodifiableSet.add(10); 8 | } 9 | -------------------------------------------------------------------------------- /pubspec.lock: -------------------------------------------------------------------------------- 1 | # Generated by pub 2 | # See https://dart.dev/tools/pub/glossary#lockfile 3 | packages: 4 | lints: 5 | dependency: "direct dev" 6 | description: 7 | name: lints 8 | url: "https://pub.dartlang.org" 9 | source: hosted 10 | version: "2.0.0" 11 | sdks: 12 | dart: ">=2.17.6 <3.0.0" 13 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: belajar_dart_collection 2 | description: A simple command-line application. 3 | version: 1.0.0 4 | # homepage: https://www.example.com 5 | 6 | environment: 7 | sdk: '>=2.17.6 <3.0.0' 8 | 9 | # dependencies: 10 | # path: ^1.8.0 11 | 12 | dev_dependencies: 13 | lints: ^2.0.0 14 | --------------------------------------------------------------------------------