A stream is a new member of the Java API that allows you to handle a collection of data declaratively (expressed by a query statement rather than writing an implementation on a temporary basis).
Java 7 Select a low-calorie dish name from the collection:
List<dish> lowcaloricdishes =NewArraylist<>(); for(Dish d:menu) {if(D.getcalories () < 400) {lowcaloricdishes.add (d); }} collections.sort (Lowcaloricdishes,NewComparator<dish>() { Public intCompare (Dish d1, Dish D2) {returnInteger.compare (D1.getcalories (), d2.getcalories ()); } }); List<String> Lowcaloricdishesname =NewArraylist<>(); for(Dish d:lowcaloricdishes) {Lowcaloricdishesname.add (D.getname ()); }
Java 8:
list<string> lowCaloricDishesName2 = menu.stream () d.getcalories () < . Sorted (Comparing (dish::getcalories)) . Map (dish::getname) . Collect (ToList ());
If you want the multi-core architecture to execute this code in parallel, simply change the stream () to Parallelstream ():
list<string> lowCaloricDishesName2 = menu. Parallelstream () , D.getcalories () < () . Sorted (Comparing (dish::getcalories)) . Map (dish::getname) . Collect (ToList ());
"Java 8 Combat" (iii)----flow