Names<2>

import java.util.List;
import java.util.Arrays;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Gaoo {
  public static void main(String args[]){
    List<String> names = Arrays.asList(
        "Afoo", "Bfoo",
        "Cfoo", "Dfoo",
        "Efoo", "Ffoo",
        "Agaoo");

    final Function<String, Predicate<String>> withLetter =
      letter -> name -> name.startsWith(letter);

    final long counters =
      names
      .stream()
      .filter(withLetter.apply("A"))
      .count();
    System.out.print(String.format("%d found.\n", counters));

    final List<String> bar =
      names
      .stream()
      .filter(withLetter.apply("A"))
      .collect(Collectors.toList());
    bar
    .stream()
    .forEach(name -> System.out.print(String.format("name: %s\n", name.toString())));
  }
}
f:id:blau_coerulea:20160902010324p:plain

Remove all ads