Click here to watch in Youtube :
https://www.youtube.com/watch?v=284w36fLUTQ&list=UUhwKlOVR041tngjerWxVccw
import java.util.Arrays; import java.util.List; /** * Intermediate operation : filter() */ public class StreamDemo1 { public static void main(String[] args) { List<String> list = Arrays.asList("Welcome", "apple", "to", "India"); /* * filter() operation helps eliminate elements based on certain * criteria. */ list.stream().filter(element -> !"apple".equals(element)) .forEach(element -> System.out.println(element)); } }Output
Welcome to IndiaStreamDemo2.java
import java.util.Arrays; import java.util.List; /** * Intermediate operation : map() */ public class StreamDemo2 { public static void main(String[] args) { List<String> list = Arrays.asList("Welcome", "apple", "to","India"); /* * map() operation helps map elements to the corresponding * results. */ list.stream().filter(element -> !"apple".equals(element)) .map(String::toUpperCase) .forEach(System.out::println); } }Output
WELCOME TO INDIAStreamDemo3.java
import java.util.Arrays; import java.util.List; /** * Intermediate operation :sorted() */ public class StreamDemo3 { public static void main(String[] args) { List<String> list = Arrays.asList("Ball", "Cat", "Dog", "Apple"); /* * sorted() operation helps sort elements based on certain * criteria. */ list.stream().sorted().filter((element) -> !element.startsWith("D")) .map(String::toUpperCase) .forEach(System.out::println); } }Output
APPLE BALL CATClick the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/StreamDemo_Intermediate_op_fms.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/StreamDemo_Intermediate_op_fms
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/921a65d57c0ec8a07d5edae78f1552619b89e108/BasicJava/StreamDemo_Intermediate_op_fms/?at=master
See also:
No comments:
Post a Comment