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
| main() { | |
| Set<String> names = {'Rita', 'Alex', 'Sam', 'Eva'}; | |
| var persons = <String>{}; //inferred type Set | |
| print('persons: $persons'); | |
| print('persons.length is ${persons.length}'); | |
| print('persons Type is ${persons.runtimeType}\n'); | |
| print('names: $names'); | |
| print('names.length is ${names.length}'); |
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
| main() { | |
| Set<String> nameSet = {'Rita', 'Alex', 'Sam', 'Eva'}; | |
| print('nameSet.contains(\'Sam\'): ${nameSet.contains('Sam')}\n'); | |
| nameSet.forEach((element){ | |
| print('element: $element'); | |
| }); | |
| nameSet.clear(); |
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
| main() { | |
| Set<String> nameSet = {'Rita', 'Alex', 'Sam', 'Eva'}; | |
| print('nameSet: $nameSet\n'); //{Rita, Alex, Sam, Eva} | |
| List<String> nameList = nameSet.toList(); | |
| print('nameList: $nameList\n'); //[Rita, Alex, Sam, Eva] | |
| Set<String> nameSet2 = nameList.toSet(); | |
| print('nameSet2: $nameSet2\n'); //{Rita, Alex, Sam, Eva} | |
| } |
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
| main() { | |
| var dividesBy2 = <int>{2,4,6,8,10,12,14,16,18,20}; | |
| var dividesBy3 = <int>{3,6,9,12,15,18,21}; | |
| var dividesBy6 = dividesBy2.intersection(dividesBy3); | |
| print('dividesBy6: $dividesBy6\n'); | |
| var doesntDivideBy6 = dividesBy2.difference(dividesBy3); | |
| print('doesntDivideBy6: $doesntDivideBy6\n'); | |
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
| main() { | |
| var list = ['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon']; | |
| for (var item in list){ | |
| print('${list.indexOf(item)}: $item'); | |
| } | |
| } |
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
| import 'package:flutter/material.dart'; | |
| void main() => runApp(MyApp()); | |
| /// This Widget is the main application widget. | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( |
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(){ | |
| Map<String, int> scores = {'Bob': 300}; | |
| print('Initial state of the scores Map: $scores'); | |
| for (var key in ['Bob', 'Rohan', 'Sophena']) { | |
| scores.putIfAbsent(key, () => key.length); | |
| } | |
| for (MapEntry entry in scores.entries){ | |
| print('scores[\'${entry.key}\']: ${entry.value}'); |
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(){ | |
| Map map1 = {1: 'one', 2: 'two'}; | |
| Map map2 = {3: 'three', 4: 'four'}; | |
| Map map3 = {...map1, ...map2}; | |
| print('map1: $map1'); | |
| print('map2: $map2'); | |
| print('map3: $map3'); | |
| } |
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(){ | |
| FullName myName = FullName('Tailor', 'VJ'); | |
| print(myName); | |
| } | |
| class FullName{ | |
| String firstName; | |
| String lastName; | |
| FullName(this.firstName, this.lastName); | |
| String toString(){ |
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() { | |
| List<FullName> fullNamesList = [FullName('Abe','Lincoln'), FullName('Babe', 'Ruth'), FullName('Carry', 'Bradshaw'),]; | |
| print ('fullNamesList:\n${fullNamesList.toString()}\n'); | |
| fullNamesList.sort((a,b) => a.lastName.compareTo(b.lastName)); | |
| print ('fullNamesList after sort by lastName:\n$fullNamesList\n'); | |
| fullNamesList.sort((a,b) => a.firstName.compareTo(b.firstName)); | |
| print ('fullNamesList after sort by firstName:\n$fullNamesList\n'); | |
| } |