OnJava8-Examples/streams/SpecialCollector.java

25 lines
638 B
Java
Raw Normal View History

2015-11-14 16:18:05 -08:00
// streams/SpecialCollector.java
// (c)2021 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
2016-09-23 13:23:35 -06:00
// Visit http://OnJava8.com for more book information.
2015-11-14 16:18:05 -08:00
import java.util.*;
import java.util.stream.*;
public class SpecialCollector {
2016-01-25 18:05:55 -08:00
public static void
main(String[] args) throws Exception {
2015-11-14 16:18:05 -08:00
ArrayList<String> words =
FileToWords.stream("Cheese.dat")
.collect(ArrayList::new,
ArrayList::add,
ArrayList::addAll);
2017-01-20 21:30:44 -08:00
words.stream()
.filter(s -> s.equals("cheese"))
.forEach(System.out::println);
2015-11-14 16:18:05 -08:00
}
}
/* Output:
cheese
cheese
*/