Learn Java 8 streams with an example - print odd/even numbers from Array and List
Example 1: Java 8 program to print odd numbers from a List import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; /*Java 8 Program to find Odd Numbers from a List*/ public class DriverClass { public static void main( String [] args) { List < Integer > numbers = Arrays. asList( 1 , 4 , 8 , 40 , 11 , 22 , 33 , 99 ); List < Integer > oddNumbers = numbers.stream(). filter(o -> o % 2 != 0 ). collect(Collectors.toList()); System.out.println(oddNumbers); } } 1. Initialize List using Arrays.asList() method. Java's built-in Arrays.asList() method converts an array into a list. This method takes an array as an argument and returns a List object. 2. Java List interface provides stream() method which returns a sequential Stream with list of Integer as its source. 3. The Java stream filter() method allow
Thank you for putting all these strategies into a very readable place. It shows your ability and great skills. keep sharing such articles in future.
ReplyDeletebest web development company
Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you Best ecommerce website development services service provider.
ReplyDeleteGreat article by the great author, it is very massive and informative but still preaches the way to sounds like that it has some beautiful thoughts described so I really appreciate this article. Best it support jacksonville service provider.
ReplyDeleteIt’s actually a great and helpful piece of info. I’m happy that you just shared this helpful info with us. Please keep us informed like this. Thanks for sharing! Best government jobs in karachi service provider.
ReplyDelete
ReplyDeleteAfter a long time, I read a very beautiful and very ismportant article that I enjoyed reading. I have found that this article has many important points, I sincerely thank the admin of this website for sharing it. Best website designing company in noida service provider
ReplyDeleteGreat article by the great author, it is very massive and informative but still preaches the way to sounds like that it has some beautiful thoughts described so I really appreciate this article. Best how to start an online business in malaysia Services Provider