נבנה על ידיBuilt by Ariel Yohimovich
collect:Collectors: Recipes for collect:filter משאיר רק מה שאחרי 1900, map הופך ספר לכותר, sorted ממיין, ו-toList אוסף.The Stream goes book by book: filter keeps what's after 1900, map turns a book into its title, sorted sorts, and toList collects.filter נקראת על כל ספר.Watch the simulation: filter's lambda is called on each book.filter משאיר רק מה שאחרי 1900, map הופך ספר לכותר, sorted ממיין, ו-toList אוסף. הרשימה המקורית לא משתנה. צפו בסימולציה: הלמבדה של filter נקראת על כל ספר.The Stream goes book by book: filter keeps what's after 1900, map turns a book into its title, sorted sorts, and toList collects. The original list doesn't change. Watch the simulation: filter's lambda is called on each book.mapToInt נותן IntStream עם sum, average, min.mapToInt gives an IntStream with sum, average, min.average מחזיר OptionalDouble (אולי אין ספרים), ולכן orElse(0).average returns an OptionalDouble (maybe there are no books), hence orElse(0).reduce מצמצם הכול לערך אחד.reduce folds everything into one value.mapToInt נותן IntStream עם sum, average, min. average מחזיר OptionalDouble (אולי אין ספרים), ולכן orElse(0). reduce מצמצם הכול לערך אחד.mapToInt gives an IntStream with sum, average, min. average returns an OptionalDouble (maybe there are no books), hence orElse(0). reduce folds everything into one value.groupingBy(Book::author, TreeMap::new, counting()) בונה מפה ממוינת מסופר לכמות.groupingBy(Book::author, TreeMap::new, counting()) builds a sorted map from author to count.joining מחבר מחרוזות עם מפריד, תחילית וסיומת.joining glues strings with a separator, prefix and suffix.groupingBy(Book::author, TreeMap::new, counting()) בונה מפה ממוינת מסופר לכמות. joining מחבר מחרוזות עם מפריד, תחילית וסיומת.groupingBy(Book::author, TreeMap::new, counting()) builds a sorted map from author to count. joining glues strings with a separator, prefix and suffix.findFirst מחזיר Optional: אולי מצאנו, אולי לא.findFirst returns an Optional: maybe found, maybe not.map(...).orElse("?") מטפל בשני המקרים בלי if (x != null).map(...).orElse("?") handles both cases with no if (x != null).findFirst מחזיר Optional: אולי מצאנו, אולי לא. map(...).orElse("?") מטפל בשני המקרים בלי if (x != null).findFirst returns an Optional: maybe found, maybe not. map(...).orElse("?") handles both cases with no if (x != null).count() הוא פעולת סיום וסוגר את ה-Stream.count() is a terminal operation and closes the Stream.count() הוא פעולת סיום וסוגר את ה-Stream. השימוש השני בו זורק חריגה.count() is a terminal operation and closes the Stream. Using it a second time throws.summaryStatistics() הדפיסו 4 books, rating 3-5, avg 4.25. מצאו את הטוב ביותר (דירוג, ובשוויון השנה המאוחרת): Best: Dune. ואז את הסופרים בלי כפולים, ממוינים: Austen | Herbert | Joyce.With summaryStatistics() print 4 books, rating 3-5, avg 4.25. Find the best (rating, ties by the later year): Best: Dune. Then the authors without duplicates, sorted: Austen | Herbert | Joyce.collect:Collectors: Recipes for collect:filter משאיר רק מה שאחרי 1900, map הופך ספר לכותר, sorted ממיין, ו-toList אוסף.The Stream goes book by book: filter keeps what's after 1900, map turns a book into its title, sorted sorts, and toList collects.filter נקראת על כל ספר.Watch the simulation: filter's lambda is called on each book.mapToInt נותן IntStream עם sum, average, min.mapToInt gives an IntStream with sum, average, min.average מחזיר OptionalDouble (אולי אין ספרים), ולכן orElse(0).average returns an OptionalDouble (maybe there are no books), hence orElse(0).reduce מצמצם הכול לערך אחד.reduce folds everything into one value.groupingBy(Book::author, TreeMap::new, counting()) בונה מפה ממוינת מסופר לכמות.groupingBy(Book::author, TreeMap::new, counting()) builds a sorted map from author to count.joining מחבר מחרוזות עם מפריד, תחילית וסיומת.joining glues strings with a separator, prefix and suffix.findFirst מחזיר Optional: אולי מצאנו, אולי לא.findFirst returns an Optional: maybe found, maybe not.map(...).orElse("?") מטפל בשני המקרים בלי if (x != null).map(...).orElse("?") handles both cases with no if (x != null).count() הוא פעולת סיום וסוגר את ה-Stream.count() is a terminal operation and closes the Stream.books.stream().filter(b -> b.year() > 1900) לבד?What does books.stream().filter(b -> b.year() > 1900) return on its own?list.stream().map(String::length).toList() משנה את list?Does list.stream().map(String::length).toList() change list?findFirst() על Stream ריק מחזיר?findFirst() on an empty Stream returns?nullnullOptional.empty()Optional.empty()Optional.empty()Optional.empty()filter משאיר רק מה שאחרי 1900, map הופך ספר לכותר, sorted ממיין, ו-toList אוסף.The Stream goes book by book: filter keeps what's after 1900, map turns a book into its title, sorted sorts, and toList collects.mapToInt נותן IntStream עם sum, average, min.mapToInt gives an IntStream with sum, average, min.groupingBy(Book::author, TreeMap::new, counting()) בונה מפה ממוינת מסופר לכמות.groupingBy(Book::author, TreeMap::new, counting()) builds a sorted map from author to count.findFirst מחזיר Optional: אולי מצאנו, אולי לא.findFirst returns an Optional: maybe found, maybe not.count() הוא פעולת סיום וסוגר את ה-Stream.count() is a terminal operation and closes the Stream.נבנה על ידיBuilt by Ariel Yohimovich