IntSummaryStatistics getMax() method in Java with ExamplesThe Java IntSummaryStatistics class's getMax() function is used to retrieve the maximum number of records in this IntSummaryStatistics. Syntax: Parameter: There are no values that can be passed as parameters to this method. Return Value: The maximum number of records in this IntSummaryStatistics are returned by this method. Example 1:The program shows how to use Java's IntSummaryStatistics class to determine the maximum value in a stream of integers. It uses a collection of integer values to start an IntStream and the summaryStatistics() function to collect stream statistics. The maximum value is one of the statistics that are included in the IntSummaryStatistics object that is returned by this method. Next, we call this object's getMax() method to get the maximum value. Implementation: FileName: MaximumSummaryExample1.java Output: The Maximum value from the IntStream is: 60 Example 2:The program shows how to get the maximum value in a list of integers using the IntSummaryStatistics class. It initializes a list of integers and an IntSummaryStatistics object. The list is traversed using an iterator, and the accept() method is used to add each number to the IntSummaryStatistics object. The getMax() method is used to acquire the maximum value once all integers have been processed. Implementation: FileName: MaximumSummaryExample2.java Output: The Maximum value from the IntStream is given by : 60 |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India