Last active
October 4, 2019 12:14
-
-
Save jsuryahyd/bb206202722be44482db5a397c283411 to your computer and use it in GitHub Desktop.
dart lists as practiced on dart pad[https://dartpad.dartlang.org/](https://dartpad.dartlang.org/)
This file contains 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 | |
// final List<dynamic> myNums = ["1", "whatever", {}]; | |
// // final List<dynamic> myNums = const ["1","whatever",{}]; | |
// myNums.add("lskf"); | |
// // myNums = [...myNums,"lskf"]; | |
// print(myNums); | |
// //2 | |
// List<int> nums = List(5); | |
// print(nums); | |
// //3 | |
// List<String> words = List.filled(5,"hello",growable:false); | |
// words.add("bolo");//throws error, since growable:false | |
// print(words); | |
// //4 | |
// List<String> newWords = List.generate(4,(idx)=>idx.toString(),growable:true); | |
// newWords.add("what?"); | |
// print(newWords); | |
// //5 | |
// List<dynamic> fromList = List.from(List.filled(5,"whatever"),growable:false); | |
// print(fromList); | |
//6 | |
List myList = ["kasd","lksjdfl","---","+++"]; | |
print(myList.any((i)=>i.length > 3)); | |
print(myList.every((i)=>i.length > 3)); | |
// print(myList.expand((item)=>[item,item]).runtimeType);//ExpandIterable<dynamic, dynamic> | |
print(myList.expand((item)=>[item,item]).toList()); | |
print(myList.reduce((acc,item)=>acc + "," +item)); | |
print(myList.fold("are the items.",(acc,i){ return i +", "+ acc;}));//first Arg will come at last.(?!) | |
print(myList.map((i)=>i+";").toList()); | |
print(myList.followedBy(["bla bla","boo yah!"]).toList()); | |
myList.addAll(["new1","new2"]); | |
print(myList); | |
print(myList.take(2).toList()); | |
myList.forEach((item){ | |
print(item); | |
}); | |
print(myList.remove("new1"));//@returns true; | |
print(myList); | |
print(myList.removeAt(4));//@returns item removed | |
print(myList); | |
print("-\\_()_/-"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment