Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dart forEach() on a List/Set
main() {
List<String> list = new List<String>();
list.add('one');
list.add('two');
list.add('twelve');
list.forEach((element) => print(element));
Set<String> set = Set.from(list);
set.forEach((element) => print(element));
}
@coeneivan

This comment has been minimized.

Copy link

@coeneivan coeneivan commented Mar 26, 2019

Thanks for this :)

@nehal2

This comment has been minimized.

Copy link

@nehal2 nehal2 commented Apr 4, 2019

thanks sir

@0x77dev

This comment has been minimized.

Copy link

@0x77dev 0x77dev commented May 21, 2019

THNK

@code4fish

This comment has been minimized.

Copy link

@code4fish code4fish commented May 28, 2019

Neat, thanks!

@MRizwanAnsar

This comment has been minimized.

Copy link

@MRizwanAnsar MRizwanAnsar commented Jun 10, 2019

Thanks

@fahjan

This comment has been minimized.

Copy link

@fahjan fahjan commented Jun 13, 2019

BIG thanks

@zwells0225

This comment has been minimized.

Copy link

@zwells0225 zwells0225 commented Jul 2, 2019

LOL, this was posted 8 years ago, and everyone is just now commenting probably because of Flutter!

@Samjay1

This comment has been minimized.

Copy link

@Samjay1 Samjay1 commented Jul 8, 2019

thanks

@thesensei254

This comment has been minimized.

Copy link

@thesensei254 thesensei254 commented Jul 30, 2019

@zwells0225 Two more questions come up, how old is github and how old am I? lol

@soroda

This comment has been minimized.

Copy link

@soroda soroda commented Aug 11, 2019

cool !

@Zeeshan0201

This comment has been minimized.

Copy link

@Zeeshan0201 Zeeshan0201 commented Aug 28, 2019

LOL, this was posted 8 years ago, and everyone is just now commenting probably because of Flutter!

@zwells0225 alright 😄

@Zeeshan0201

This comment has been minimized.

Copy link

@Zeeshan0201 Zeeshan0201 commented Aug 28, 2019

@zwells0225 Two more questions come up, how old is github and how old am I? lol
@Ngondo haha

@xkdcc

This comment has been minimized.

Copy link

@xkdcc xkdcc commented Dec 11, 2019

LOL, this was posted 8 years ago, and everyone is just now commenting probably because of Flutter!

True 😄

@gakyoo

This comment has been minimized.

Copy link

@gakyoo gakyoo commented Jan 22, 2020

Definitely because of Flutter.

@Kantulaev

This comment has been minimized.

Copy link

@Kantulaev Kantulaev commented Jan 23, 2020

Yea flutter

@Javitonito-Javier

This comment has been minimized.

Copy link

@Javitonito-Javier Javitonito-Javier commented Feb 25, 2020

thx for sharing

@ars27196

This comment has been minimized.

Copy link

@ars27196 ars27196 commented Mar 2, 2020

Thanks, I don't even know dart was this old.

@buiquangbao

This comment has been minimized.

Copy link

@buiquangbao buiquangbao commented Apr 7, 2020

I came here because of Flutter...

Created 9 years ago

@anhpv315

This comment has been minimized.

Copy link

@anhpv315 anhpv315 commented Apr 21, 2020

thanks

@idrisov-ri

This comment has been minimized.

Copy link

@idrisov-ri idrisov-ri commented Apr 23, 2020

yeap, Flutter 😄

@giuliano-oliveira

This comment has been minimized.

Copy link

@giuliano-oliveira giuliano-oliveira commented May 7, 2020

thnks my dude, yup, flutter as well

@ench0

This comment has been minimized.

Copy link

@ench0 ench0 commented May 11, 2020

What is Dart? :-)

@oonxselhakeem

This comment has been minimized.

Copy link

@oonxselhakeem oonxselhakeem commented Jul 6, 2020

flutter is here

@adityachaudhari

This comment has been minimized.

Copy link

@adityachaudhari adityachaudhari commented Jul 24, 2020

LOL, this was posted 8 years ago, and everyone is just now commenting probably because of Flutter!

haha True !!

@lmas3009

This comment has been minimized.

Copy link

@lmas3009 lmas3009 commented Aug 2, 2020

Thanks

@AdityaBelani

This comment has been minimized.

Copy link

@AdityaBelani AdityaBelani commented Aug 26, 2020

Still Commenting!

@vaibhav-yb

This comment has been minimized.

Copy link

@vaibhav-yb vaibhav-yb commented Aug 28, 2020

Hey, what if we want to execute a block of comments using forEach? Would the following be valid?

list.forEach( (item) {
//do something
//do something else
});
@Babwenbiber

This comment has been minimized.

Copy link

@Babwenbiber Babwenbiber commented Nov 12, 2020

@fourpointfour
list.forEach((item) => print(item)); is nothing else then list.forEach((item) { return print(item);});
since the return type is void, you are not using the return type anyways. So your syntax is totally valid.

@leenabhandari

This comment has been minimized.

Copy link

@leenabhandari leenabhandari commented Nov 30, 2020

cool

@alperenarc

This comment has been minimized.

Copy link

@alperenarc alperenarc commented Dec 7, 2020

You can use set.forEach(print) instead of set.forEach((element) => print(element))

@yeicobF

This comment has been minimized.

Copy link

@yeicobF yeicobF commented May 13, 2021

Great!

@luigi-cuomo-3r

This comment has been minimized.

Copy link

@luigi-cuomo-3r luigi-cuomo-3r commented Jun 8, 2021

Awesome!

@julioagilez

This comment has been minimized.

Copy link

@julioagilez julioagilez commented Jun 16, 2021

We still use it in 2021, thanks man!

@hammadsyr

This comment has been minimized.

Copy link

@hammadsyr hammadsyr commented Oct 7, 2021

i think we should avoid using set for variable name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment