Click here to watch in Youtube :
https://www.youtube.com/watch?v=QGVLDmVMN4o&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Terminal operations[foreach and toArray] in Java 8 Stream | Streams in Java 8 |
import java.util.stream.Stream; public class StreamForEachDemo { public static void main(String[] args) { Stream<String> stream = Stream.of("peter", "Juli", "David"); /* * iterates over each element using forEach: */ stream.forEach(System.out::println); } }Output
peter Juli DavidStreamToArrayDemo.java
import java.util.stream.Stream; public class StreamToArrayDemo { public static void main(String[] args) { Object[] objectArray = Stream.of(1, 2, 3, 4, 5).toArray(); for (Object object : objectArray) { System.out.println(object); } System.out.println("-----------------------------------"); String[] upperCaseNameArray = (String[]) Stream.of("Peter", "Juli", "Ram") .map(s -> s.toUpperCase()) .toArray(String[]::new); for (String name : upperCaseNameArray) { System.out.println(name); } } }Output
1 2 3 4 5 ----------------------------------- PETER JULI RAMClick the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/StreamDemo_terOp_fe_toArray_App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StreamDemo_terOp_fe_toArray_App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/21c94b97f3d45cf2018afb81344804fbe9e1995b/BasicJava/StreamDemo_terOp_fe_toArray_App/?at=master
See also:
No comments:
Post a Comment