Names

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

public class Names
{
  public static void main(String args[]) {
    final List<String> names = Arrays.asList("kOyOmI", "kAHo", "MisA", "cRisTiNa");

    names.stream()
      .map(String::toUpperCase)
      .forEach(n->System.out.print(n + " "));
    System.out.print("\n");

    names.stream()
      .map(n->n.length())
      .forEach(n->System.out.print(n + " "));
    System.out.print("\n");

    final List<String> startsWithK =
      names.stream()
      .filter(n->n.startsWith("k"))
      .collect(Collectors.toList());
    System.out.print(String.format("Found %d names startsWith k\n", startsWithK.size()));

    final Predicate<String> startsWithM = name -> name.startsWith("M");
    final long countNameStartWithM =
      names.stream()
      .filter(startsWithM)
      .count();
    System.out.print(String.format("Found %d names startsWith M\n", countNameStartWithM));
  }
}

Remove all ads