{"id":104157,"date":"2021-08-13T11:00:00","date_gmt":"2021-08-13T08:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=104157"},"modified":"2021-12-17T13:30:44","modified_gmt":"2021-12-17T11:30:44","slug":"java-8-stream-min-max-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/","title":{"rendered":"Java 8 Stream &#8211; min() &#038; max() Tutorial"},"content":{"rendered":"<p>Hello. In this tutorial, we will explain the min() and max() methods introduced in java 8.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-1-introduction\">1. Introduction<\/h2>\n<p>Before diving deep into the practice stuff let us understand the <code>min()<\/code> and <code>max()<\/code> methods introduced in java8 programming.<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>Stream.min()<\/strong> &#8211; Returns the minimum element of the stream according to the provided comparator.\n<ul>\n<li>Represented by the code syntax &#8211; <code>Optional&lt;T&gt; min(Comparator&lt;? super T&gt; comparator)<\/code><\/li>\n<li>It is a terminal operation that combines the stream elements and returns the final result<\/li>\n<li>Returns an optional or an empty optional if the stream is empty<\/li>\n<li>Throw the <code>NullPointerException<\/code> if the smallest element is <code>null<\/code><\/li>\n<\/ul>\n<\/li>\n<li><strong>Stream.max()<\/strong> &#8211; Returns the maximum element of the stream according to the provided comparator.\n<ul>\n<li>Represented by the code syntax &#8211; <code>Optional&lt;T&gt; max(Comparator&lt;? super T&gt; comparator)<\/code><\/li>\n<li>It is a terminal operation that combines the stream elements and returns the final result<\/li>\n<li>Returns an optional or an empty optional if the stream is empty<\/li>\n<li>Throw the <code>NullPointerException<\/code> if the largest element is <code>null<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"wp-block-image\">\n<figure class=\"alignright size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\"><img decoding=\"async\" width=\"150\" height=\"150\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" alt=\"java 8 min\" class=\"wp-image-1204\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg 150w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo-70x70.jpg 70w\" sizes=\"(max-width: 150px) 100vw, 150px\" \/><\/a><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-2-practice\">2. Practice<\/h2>\n<p>Let us dive into some practice stuff from here and I am assuming that you already have the Java 1.8 or greater installed in your local machine. I am using <a href=\"https:\/\/www.jetbrains.com\/idea\/\" target=\"_blank\" rel=\"noopener\">JetBrains IntelliJ IDEA<\/a> as my preferred IDE. You&#8217;re free to choose the IDE of your choice.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-2-1-find-min-and-max-integer\">2.1 Find min and max integer<\/h3>\n<p>Create a java file in the <code>com.java8<\/code> package and add the following code to it.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>MinMaxDemo1.java<\/em><\/span><\/p>\n<pre class=\"wp-block-preformatted brush:java; wrap-lines:false;\">package com.java8;\n\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.Optional;\n\n\/*\n * Stream.min() - Returns the minimum element of this stream according to the provided comparator.\n * Stream.max() - Returns the maximum element of this stream according to the provided comparator.\n *\/\npublic class MinMaxDemo1 {\n\t\n\tprivate static void findMinAndMaxForIntegers() {\n\t\tSystem.out.println(\"---- Min and Max for integer ----\");\n\t\t\n\t\tfinal List&lt;Integer&gt; integers = Arrays.asList(6, 5, 20, 2, 1);\n\t\t\/\/ integer comparator\n\t\tfinal Comparator&lt;Integer&gt; comparator = Comparator.comparing(Integer::intValue);\n\t\t\n\t\tfinal Optional&lt;Integer&gt; min = integers.stream().min(comparator);\n\t\t\/\/ handling the sonar issue to perform ifPresent check before fetch\n\t\tmin.ifPresent(val -&gt; System.out.println(\"Stream.min():- \" + val));\n\t\t\n\t\tfinal Optional&lt;Integer&gt; max = integers.stream().max(comparator);\n\t\t\/\/ handling the sonar issue to perform ifPresent check before fetch\n\t\tmax.ifPresent(val -&gt; System.out.println(\"Stream.max():- \" + val));\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tfindMinAndMaxForIntegers();\n\t}\n}\n<\/pre>\n<p>Run the file and if everything goes well the following output will be logged in the IDE console.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline;\"><em>Console output<\/em><\/span><\/p>\n<pre class=\"wp-block-preformatted brush:plain; wrap-lines:false;\">---- Min and Max for integer ----\nStream.min():- 1\nStream.max():- 20\n<\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-2-2-find-min-and-max-string\">2.2 Find min and max string<\/h3>\n<p>Create a java file in the <code>com.java8<\/code> package and add the following code to it.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>MinMaxDemo2.java<\/em><\/span><\/p>\n<pre class=\"wp-block-preformatted brush:java; wrap-lines:false;\">package com.java8;\n\nimport java.util.Arrays;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.Optional;\n\n\/*\n * Stream.min() - Returns the minimum element of this stream according to the provided comparator.\n * Stream.max() - Returns the maximum element of this stream according to the provided comparator.\n *\/\npublic class MinMaxDemo2 {\n\n\tprivate static void findMinAndMaxForStrings() {\n\t\tSystem.out.println(\"---- Min and Max for string ----\");\n\t\t\n\t\tfinal List&lt;String&gt; strings = Arrays.asList(\"A\", \"F\", \"Z\", \"B\", \"P\");\n\t\t\/\/ string comparator\n\t\tfinal Comparator&lt;String&gt; comparator = Comparator.comparing(String::valueOf);\n\t\t\n\t\tfinal Optional&lt;String&gt; min = strings.stream().min(comparator);\n\t\t\/\/ handling the sonar issue to perform ifPresent check before fetch\n\t\tmin.ifPresent(val -&gt; System.out.println(\"Stream.min():- \" + val));\n\t\t\n\t\tfinal Optional&lt;String&gt; max = strings.stream().max(comparator);\n\t\t\/\/ handling the sonar issue to perform ifPresent check before fetch\n\t\tmax.ifPresent(val -&gt; System.out.println(\"Stream.max():- \" + val));\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tfindMinAndMaxForStrings();\n\t}\n}\n<\/pre>\n<p>Run the file and if everything goes well the following output will be logged in the IDE console.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Console output<\/em><\/span><\/p>\n<pre class=\"wp-block-preformatted brush:plain; wrap-lines:false;\">---- Min and Max for string ----\nStream.min():- A\nStream.max():- Z\n<\/pre>\n<h3 class=\"wp-block-heading\" id=\"h-2-3-find-min-and-max-object\">2.3 Find min and max object<\/h3>\n<p>Create a java file in the <code>com.java8<\/code> package and add the following code to it.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>MinMaxDemo3.java<\/em><\/span><\/p>\n<pre class=\"wp-block-preformatted brush:java; wrap-lines:false;\">package com.java8;\n\nimport java.util.ArrayList;\nimport java.util.Comparator;\nimport java.util.List;\nimport java.util.Optional;\n\n\/*\n * Stream.min() - Returns the minimum element of this stream according to the provided comparator.\n * Stream.max() - Returns the maximum element of this stream according to the provided comparator.\n *\/\npublic class MinMaxDemo3 {\n\n\tprivate static void findMinAndMaxByName(final List&lt;Student&gt; students) {\n\t\tSystem.out.println(\"\\nMin and max student by name\");\n\t\t\/\/ student name comparator\n\t\tfinal Comparator&lt;Student&gt; name = Comparator.comparing(Student::getName);\n\n\t\tfinal Optional&lt;Student&gt; min = students.stream().min(name);\n\t\t\/\/ handling the sonar issue to perform ifPresent check before fetch\n\t\tmin.ifPresent(val -&gt; System.out.println(\"Stream.min():- \" + val.toString()));\n\n\t\tfinal Optional&lt;Student&gt; max = students.stream().max(name);\n\t\t\/\/ handling the sonar issue to perform ifPresent check before fetch\n\t\tmax.ifPresent(val -&gt; System.out.println(\"Stream.max():- \" + val.toString()));\n\t}\n\n\tprivate static void findMinAndMaxByAge(final List&lt;Student&gt; students) {\n\t\tSystem.out.println(\"\\nMin and max student by age\");\n\t\t\/\/ student age comparator\n\t\tfinal Comparator&lt;Student&gt; age = Comparator.comparing(Student::getAge);\n\n\t\tfinal Optional&lt;Student&gt; minAge = students.stream().min(age);\n\t\t\/\/ handling the sonar issue to perform ifPresent check before fetch\n\t\tminAge.ifPresent(val -&gt; System.out.println(\"Stream.min():- \" + val.toString()));\n\n\t\tfinal Optional&lt;Student&gt; maxAge = students.stream().max(age);\n\t\t\/\/ handling the sonar issue to perform ifPresent check before fetch\n\t\tmaxAge.ifPresent(val -&gt; System.out.println(\"Stream.min():- \" + val.toString()));\n\t}\n\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"---- Min and Max for object ----\");\n\t\t\n\t\t\/\/ student list\n\t\tfinal List&lt;Student&gt; students = new ArrayList&lt;&gt;();\n\t\tstudents.add(new Student(\"John\", 41));\n\t\tstudents.add(new Student(\"Jane\", 20));\n\t\tstudents.add(new Student(\"Adam\", 17));\n\t\tstudents.add(new Student(\"Eve\", 3));\n\t\tstudents.add(new Student(\"Mathew\", 10));\n\t\t\n\t\tfindMinAndMaxByName(students);\n\t\tfindMinAndMaxByAge(students);\n\t}\n}\n\nclass Student {\n\tprivate final String name;\n\tprivate final int age;\n\n\tpublic Student(final String name, final int age) {\n\t\tthis.name = name;\n\t\tthis.age = age;\n\t}\n\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\n\tpublic int getAge() {\n\t\treturn age;\n\t}\n\n\t@Override\n\tpublic String toString() {\n\t\treturn \"Student [name=\" + name + \", age=\" + age + \"]\";\n\t}\n}\n<\/pre>\n<p>Run the file and if everything goes well the following output will be logged in the IDE console.[ulp id=&#8217;mp4qw6feirku6wM7&#8242; name=&#8217;Java 8 Features Inline&#8217;]<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Console output<\/em><\/span><\/p>\n<pre class=\"wp-block-preformatted brush:plain; wrap-lines:false;\">---- Min and Max for object ----\n\nMin and max student by name\nStream.min():- Student [name=Adam, age=17]\nStream.max():- Student [name=Mathew, age=10]\n\nMin and max student by age\nStream.min():- Student [name=Eve, age=3]\nStream.min():- Student [name=John, age=41]\n<\/pre>\n<p>That is all for this tutorial and I hope the article served you with whatever you were looking for. Happy Learning and do not forget to share!<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-3-summary\">3. Summary<\/h2>\n<p>In this tutorial, we learned the <code>min()<\/code> and <code>max()<\/code> methods introduced in java8 programming along with the implementation. The <code>min()<\/code> method helps to determine the smallest element from the given stream on the basis of a comparator. Similarly, the <code>max<\/code> method helps to determine the largest element from the given stream on the basis of a comparator. You can download the source code from the <a href=\"#projectDownload\">Downloads<\/a> section.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-4-download-the-eclipse-project\"><a name=\"projectDownload\"><\/a>4. Download the Eclipse Project<\/h2>\n<p>This was a tutorial about the <code>min()<\/code> and <code>max()<\/code> methods in java 8.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>You can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/08\/Java-8-Stream-min-max-Tutorial.zip\"><strong>Java 8 Stream &#8211; min() &amp; max() Tutorial<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello. In this tutorial, we will explain the min() and max() methods introduced in java 8. 1. Introduction Before diving deep into the practice stuff let us understand the min() and max() methods introduced in java8 programming. Stream.min() &#8211; Returns the minimum element of the stream according to the provided comparator. Represented by the code &hellip;<\/p>\n","protected":false},"author":119,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[478,774,212],"class_list":["post-104157","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-java","tag-java-8","tag-java-basics-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java 8 Stream - min() &amp; max() - Examples Java Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Hello. In this tutorial, we will explain the min() and max() methods introduced in java 8. 1. Introduction Before diving deep into the practice stuff let\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java 8 Stream - min() &amp; max() - Examples Java Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Hello. In this tutorial, we will explain the min() and max() methods introduced in java 8. 1. Introduction Before diving deep into the practice stuff let\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-13T08:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-17T11:30:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Yatin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Yatin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/\"},\"author\":{\"name\":\"Yatin\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\"},\"headline\":\"Java 8 Stream &#8211; min() &#038; max() Tutorial\",\"datePublished\":\"2021-08-13T08:00:00+00:00\",\"dateModified\":\"2021-12-17T11:30:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/\"},\"wordCount\":453,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"Java\",\"Java 8\",\"java basics\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/\",\"name\":\"Java 8 Stream - min() & max() - Examples Java Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2021-08-13T08:00:00+00:00\",\"dateModified\":\"2021-12-17T11:30:44+00:00\",\"description\":\"Hello. In this tutorial, we will explain the min() and max() methods introduced in java 8. 1. Introduction Before diving deep into the practice stuff let\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Java 8 Stream &#8211; min() &#038; max() Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13\",\"name\":\"Yatin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg\",\"caption\":\"Yatin\"},\"description\":\"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).\",\"sameAs\":[\"https:\/\/www.javacodegeeks.com\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java 8 Stream - min() & max() - Examples Java Code Geeks - 2026","description":"Hello. In this tutorial, we will explain the min() and max() methods introduced in java 8. 1. Introduction Before diving deep into the practice stuff let","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Java 8 Stream - min() & max() - Examples Java Code Geeks - 2026","og_description":"Hello. In this tutorial, we will explain the min() and max() methods introduced in java 8. 1. Introduction Before diving deep into the practice stuff let","og_url":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2021-08-13T08:00:00+00:00","article_modified_time":"2021-12-17T11:30:44+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Yatin","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Yatin","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/"},"author":{"name":"Yatin","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13"},"headline":"Java 8 Stream &#8211; min() &#038; max() Tutorial","datePublished":"2021-08-13T08:00:00+00:00","dateModified":"2021-12-17T11:30:44+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/"},"wordCount":453,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["Java","Java 8","java basics"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/","name":"Java 8 Stream - min() & max() - Examples Java Code Geeks - 2026","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2021-08-13T08:00:00+00:00","dateModified":"2021-12-17T11:30:44+00:00","description":"Hello. In this tutorial, we will explain the min() and max() methods introduced in java 8. 1. Introduction Before diving deep into the practice stuff let","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-8-stream-min-max-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"Java 8 Stream &#8211; min() &#038; max() Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/9874407a37b028e8be3276e2b5960d13","name":"Yatin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2023\/09\/cropped-Yatin-Batra_avatar_1515758148-96x96.jpg","caption":"Yatin"},"description":"An experience full-stack engineer well versed with Core Java, Spring\/Springboot, MVC, Security, AOP, Frontend (Angular &amp; React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).","sameAs":["https:\/\/www.javacodegeeks.com"],"url":"https:\/\/examples.javacodegeeks.com\/author\/yatin-batra\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/104157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/119"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=104157"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/104157\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=104157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=104157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=104157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}