~/ learn/ java-from-zero/ cards/ Stream basics: source → intermediate → terminal
1 of 4

Type a filter-map-count pipeline on a list

Type a filter-map-count pipeline on a list

Answer

long n = names.stream() .filter(s -> s.length() > 3) .map(String::toLowerCase) .count();

Nothing runs until count() is called. filter and map are lazy registrations. count() triggers the pipeline and returns the number of elements that passed filter.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/bf4a596f-f0da-4a21-bcba-f2e1f61f1721/flashcard utf-8 LF