Java 8 features - class 31 - Collectors class - reduction, summarizing, grouping and partitioning

Поделиться
HTML-код
  • Опубликовано: 6 окт 2024
  • You can learn Java with me as the Java Programming language is being made easily. It would take a period of minimum three months and maximum 6 months to master Java. I would recommend you to watch all my videos to crack any software interviews that would require Java Programming language as a primary skill.
    Collectors class in Java 8:-
    ============================
    1. Collectors is a class in java which is available in java.util.stream package.
    2. It contains many static methods which will help you to perform some reduction operations.
    3. Please be informed that Collectors class is used to accumulate or copy the data from Stream Objects to Collection Object
    4. If you just want to copy the data from Stream objects to the Collection Object
    you can use the following methods
    Collectors.toList()
    Collectors.toSet()
    Collectors.toMap()
    5. Collectors will help you to summarize or perform some operations based on some Criteria.
    What are the basic operations that one can do with Collectors?
    1. Reducing
    2. Summarizing
    3. Grouping
    4. Partitioning
    Counting() method:-
    ====================
    In Java 8, the counting() method is part of the Collectors utility class, which provides a way to collect elements from a stream into a variety of different forms. Specifically, counting() is a collector that counts the number of elements in a stream.
    maxBy() method:-
    ==============
    In Java 8, the maxBy() method is part of the Collectors utility class and is used to find the maximum element of a stream based on a specified comparator. It returns an Optional containing the maximum element, or an empty Optional if the stream is empty.
    minBy() method:-
    ==============
    In Java 8, the minBy() method is part of the Collectors utility class and is used to find the minimum element of a stream based on a specified comparator. Similar to maxBy(), it returns an Optional containing the minimum element, or an empty Optional if the stream is empty.
    summingInt() method:-
    ===================
    In Java 8, the summingInt() method is part of the Collectors utility class. It is used to sum the integer values of elements in a stream. This collector is particularly useful when you want to aggregate values based on some property of the elements in a collection.
    averagingInt() method:-
    ===================
    In Java 8, the averagingInt() method is part of the Collectors utility class. It is used to calculate the average of integer values in a stream. This collector is particularly useful when you want to obtain the average of numeric properties from a collection of objects.
    summarizingInt() method:-
    =====================
    In Java 8, the summarizingInt() method is part of the Collectors utility class. It provides a way to gather statistics, such as count, sum, min, average, and max, for integer values in a stream. This method is particularly useful when you want a comprehensive summary of numeric data in a single operation.

Комментарии • 3

  • @JavaInterviewQuestions
    @JavaInterviewQuestions  3 дня назад

    Notes are attached in the description

  • @GADUGANESH-t9o
    @GADUGANESH-t9o 3 дня назад +1

    Hii sir please do microservice courses. You are teaching is good.

    • @JavaInterviewQuestions
      @JavaInterviewQuestions  3 дня назад

      @@GADUGANESH-t9o Thank you for comment ,I will definitely do after completing java 8 I will start design patterns