Python Java forEach equivalent -
i java programmer. started learning python few days ago. i'm wondering: there equivalents
    map.foreach(system.out::println)
 in python lambdas? or loop:
     for e in map: print(e)
there no equivalent java's imperative iterable.foreach or stream.foreach method. there's map function, analogous java's stream.map, it's applying transformations iterable. java's stream.map, doesn't apply function until perform terminal operation on return value.
you abuse map job of foreach:
list(map(print, iterable)) but it's bad idea, producing side effects function shouldn't have , building giant list don't need. it'd doing
somelist.stream().map(x -> {system.out.println(x); return x;}).collect(collectors.tolist()) in java.
the standard way in python loop:
for thing in iterable:     print(thing) 
Comments
Post a Comment