Set<String> itemToFilter = Stream.of("bat", "owl")
.collect(Collectors.toCollection(HashSet::new));
Map<String, Long> result = animals.stream()
.filter(animal -> itemToFilter.contains(animal))
.collect(Collectors.groupingBy(animal -> animal , Collectors.counting()));
System.out.println("result ="+ result);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…