OnJava8-Examples/typeinfo/PetCount4.java
2015-12-15 11:47:04 -08:00

26 lines
810 B
Java

// typeinfo/PetCount4.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
import typeinfo.pets.*;
import onjava.*;
public class PetCount4 {
public static void main(String[] args) {
TypeCounter counter = new TypeCounter(Pet.class);
Pets.stream()
.limit(20)
.peek(counter::count)
.forEach(p -> System.out.print(
p.getClass().getSimpleName() + " "));
System.out.println("\n" + counter);
}
}
/* Output:
Rat Manx Cymric Mutt Pug Cymric Pug Manx Cymric Rat
EgyptianMau Hamster EgyptianMau Mutt Mutt Cymric Mouse Pug
Mouse Cymric
{Mutt=3, Rat=2, EgyptianMau=2, Pet=20, Mouse=2, Manx=7,
Cat=9, Rodent=5, Cymric=5, Dog=6, Pug=3, Hamster=1}
*/