In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the role of stream, the new feature of java8". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the role of stream, the new feature of java8?"
Previous lumbda expressions, method references, so what's the use of writing that is incompatible with java? The answer is to work with stream, another new feature of java8.
The method of java operation set is weak * what if you want to filter out the data you want from list? Create a new collection, foreach source collection, and fill in the matching new collection, return. Stream streaming provides us with a simple and convenient method.
Static List strings = Arrays.asList ("abc", "", "bc", "efg", "abcd", "", "jkl", "abc"); / / General method strings.stream (); / / convert to stream strings.stream (). Collect (Collectors.toList ()); / / collect is converted back, and the Collectors.toList () parameter is converted to list strings.stream (). Distinct () / / deduplication / / foreach loop / / strings.stream (). ForEach (System.out::println); / / strings.stream () .forEach (data- > {/ / System.out.println (data+ "- lambda"); / /}) / filter filter / / List list= strings.stream () .filter (s-> s.contains ("a")) .filter (Collectors.toList ()); / / list.stream () .forEach (System.out::println) / map maps operation data and then assigns values to the original location / / List list= strings.stream () .map (s-> s + "after mapping") .distinct () .collect (Collectors.toList ()); / / list.stream () .forEach (System.out::println); / / limit limits the number from scratch. / / Random random = new Random (); / / random.ints () .limit (10) .forEach (System.out::println); / / strings.stream () .limit (3) .forEach (System.out::println); / / sorted sort / / strings.stream () .sorted () .forEach (System.out::println) Strings.stream () .sorted (Comparator.reverseOrder ()) .forEach (System.out::println); / / flashback / / aggregate / / Liststrings = Arrays.asList ("abc", "", "bc", "efg", "abcd", "jkl"); / / List filtered = strings.stream (). Filter (string->! string.isEmpty ()). / System.out.println ("filter list:" + filtered); / / String mergedString = strings.stream (). Filter (string->! string.isEmpty ()) .merge (Collectors.joining (",")); / / System.out.println ("merge string:" + mergedString); / / Statistics / / List numbers = Arrays.asList (3, 2, 2, 3, 7, 3, 5) / IntSummaryStatistics stats = numbers.stream (). MapToInt ((x)-> x). SummaryStatistics (); / System.out.println ("the largest number in the list:" + stats.getMax ()); / / System.out.println ("the smallest number in the list:" + stats.getMin ()); / / System.out.println ("Sum of all numbers:" + stats.getSum ()) / System.out.println ("average:" + stats.getAverage ()); thank you for reading, the above is the content of "what is the role of stream, the new feature of java8?" after the study of this article, I believe you have a deeper understanding of the role of stream, the new feature of java8, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.