CodePudding user response:
Arrays are allowed to repeat itself! You are the all data structure called an array?Statistics of this problem, is not difficult to give you an example:
Public class StreamTest {
Private final StreamThe menu=Arrays. AsList (
New Dish (" pork ", false, 800, Dish. The MEAT),
New Dish (" beef ", false, 700, Dish. The MEAT),
New Dish (" chicken ", false, 400, Dish. The MEAT),
New Dish (" French fries ", true, 530, Dish. The OTHER),
New Dish (" rice ", true, 350, Dish. The OTHER),
New Dish (" season fruit ", true, 120, Dish. The OTHER),
New Dish (" pizza ", true, 550, Dish. The OTHER),
New Dish (" prawns, "false, 300, Dish. The FISH),
New Dish (" salmon ", false, 450, Dish. The FISH)
). The stream ();
@ Test
Public void testGp () {
Final MapAllQueryParam=menu. Collect (Collectors. GroupingBy (Dish: : isVegatarian, Collectors, counting ()));
AllQueryParam. ForEach ((vegatarian, total) - & gt; {
System. The out. Println (" Dish vegatarian: "+ vegatarian +", total: "+ total);
});
//the output:
//Dish vegatarian: false, total: 5
//Dish vegatarian: true, total: 4
}
CodePudding user response:
Try the best is to do a management system, in a main method in exercise don't have much meaning