{"id":3418,"date":"2024-11-15T17:04:03","date_gmt":"2024-11-15T17:04:03","guid":{"rendered":"https:\/\/sankhamtech.com\/index.php\/content\/india\/english\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/"},"modified":"2024-11-15T17:04:43","modified_gmt":"2024-11-15T17:04:43","slug":"understanding-loops-in-java-foreach-and-lambda","status":"publish","type":"page","link":"https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/","title":{"rendered":"Understanding Loops in Java: forEach and lambda"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-page\" data-elementor-id=\"3418\" class=\"elementor elementor-3418\">\n\t\t\t\t<div class=\"elementor-element elementor-element-d73e2eb e-flex e-con-boxed e-con e-parent\" data-id=\"d73e2eb\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t<div class=\"elementor-element elementor-element-133b4ac e-con-full e-flex e-con e-child\" data-id=\"133b4ac\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-c87d0c1 elementor-hidden-mobile elementor-widget elementor-widget-text-editor\" data-id=\"c87d0c1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h6 style=\"text-align: center;\"><span style=\"text-decoration: underline;\">Lessons<\/span><\/h6>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b20ab6d elementor-hidden-desktop elementor-hidden-tablet elementor-widget elementor-widget-text-editor\" data-id=\"b20ab6d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h6 style=\"text-align: center;\"><a href=\"https:\/\/sankhamtech.com\/index.php\/content\/india\/english\/home\/free-courses\/understanding-object-oriented-programming-in-java\/\"><span style=\"text-decoration: underline;\">Lessons<\/span><\/a><\/h6>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a2aaf1b elementor-hidden-mobile elementor-widget elementor-widget-darsanam_header_menu_widget\" data-id=\"a2aaf1b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"darsanam_header_menu_widget.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"darsanam-menu-wrapper \"><div class='hamburger-icon'><i class=\"fas fa-grip-lines\"><\/i> &nbsp; <\/div><div class=\"menu-container\"><nav class='elementor-menu'><ul class='darsanam-menu-vertical'><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/setting-up-your-development-environment\/'>Setting Up Your Development Environment<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/java-basics-syntax-variables-data-types-and-operators\/'>Java Basics - Syntax, Variables, Data Types, and Operators<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-objects-and-classes-in-java\/'>Understanding Objects and Classes in Java<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-encapsulation-in-java\/'>Understanding Encapsulation in Java<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-inheritance-in-java-the-is-a-relationship\/'>Understanding Inheritance in Java: The \"Is-A\" Relationship<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-constructors-in-java-inheritance\/'>Understanding Constructors in Java Inheritance<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-access-modifiers-in-java-inheritance\/'>Understanding Access Modifiers in Java Inheritance<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-polymorphism-in-java\/'>Understanding Polymorphism in Java<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-abstract-classes-and-methods-in-java\/'>Understanding Abstract Classes and Methods in Java<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-interfaces-in-java\/'>Understanding Interfaces in Java<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-exception-handling-in-java\/'>Understanding Exception Handling in Java<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/java-collections-framework-list-set-map-and-their-implementations\/'>Java Collections Framework - List, Set, Map, and their implementations<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/' style='color: #FF7700 !important'>Understanding Loops in Java: forEach and lambda<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-the-serializable-interface-in-java\/'>Understanding the Serializable Interface in Java<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-java-beans\/'>Understanding Java Beans<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><li class='darsanam-menu-item'><a href='https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/making-api-calls-in-java-a-comprehensive-guide\/'>Making API Calls in Java: A Comprehensive Guide<\/a><i class=\"menu-icon-right fas fa-angle-right\"><\/i><\/li><\/ul><\/nav><\/div><\/div>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-0c16fc3 e-con-full e-flex e-con e-child\" data-id=\"0c16fc3\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-1f16756 elementor-widget elementor-widget-text-editor\" data-id=\"1f16756\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2>Understanding Loops in Java: forEach and lambda<\/h2><p><\/p><p><\/p><h4 class=\"wp-block-heading\"><\/h4><h4 class=\"wp-block-heading\">Part 1: Understanding forEach Loop in Java (Without Lambda)<\/h4><h4 class=\"wp-block-heading\"> <\/h4><h5 class=\"wp-block-heading\">forEach Loop Example:<\/h5><h4 class=\"wp-block-heading\"> <\/h4><pre class=\"wp-block-code\"><code>List&lt;String&gt; animals = Arrays.asList(\"Cat\", \"Dog\", \"Elephant\");\n\nfor (String animal : animals) {\n    System.out.println(animal);\n}\n<\/code><\/pre><h4 class=\"wp-block-heading\"> <\/h4><h4 class=\"wp-block-heading\">Iteration Analysis:<\/h4><h4 class=\"wp-block-heading\"> <\/h4><figure class=\"wp-block-table\"><table><thead><tr><th>Iteration<\/th><th>Explanation<\/th><th>Output<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Takes &#8220;Cat&#8221; from <code>animals<\/code>, assigns to <code>animal<\/code>.<\/td><td>Prints &#8220;Cat&#8221;<\/td><\/tr><tr><td>2<\/td><td>Takes &#8220;Dog&#8221;, assigns to <code>animal<\/code>.<\/td><td>Prints &#8220;Dog&#8221;<\/td><\/tr><tr><td>3<\/td><td>Takes &#8220;Elephant&#8221;, assigns to <code>animal<\/code>.<\/td><td>Prints &#8220;Elephant&#8221;<\/td><\/tr><\/tbody><\/table><\/figure><h4 class=\"wp-block-heading\"> <\/h4><h4 class=\"wp-block-heading\">Part 2: Lambda Function Without forEach<\/h4><h4 class=\"wp-block-heading\"> <\/h4><h5 class=\"wp-block-heading\">Lambda Function Example:<\/h5><h4 class=\"wp-block-heading\"> <\/h4><pre class=\"wp-block-code\"><code>interface StringFunction {\n    String transform(String str);\n}\n\npublic class Main {\n    public static void main(String[] args) {\n        StringFunction exclaim = (s) -&gt; s + \"!\";\n        String result = exclaim.transform(\"Hello\");\n        System.out.println(result);\n    }\n}\n<\/code><\/pre><h4 class=\"wp-block-heading\"> <\/h4><h4 class=\"wp-block-heading\">Iteration Analysis:<\/h4><h4 class=\"wp-block-heading\"> <\/h4><figure class=\"wp-block-table\"><table><thead><tr><th>Step<\/th><th>Explanation<\/th><th>Output<\/th><\/tr><\/thead><tbody><tr><td>Definition<\/td><td>Define <code>exclaim<\/code> with lambda <code>(s) -&gt; s + \"!\"<\/code>.<\/td><td>&#8211;<\/td><\/tr><tr><td>Execution<\/td><td>Apply <code>exclaim<\/code> to &#8220;Hello&#8221;, adds &#8220;!&#8221; to the end.<\/td><td>Prints &#8220;Hello!&#8221;<\/td><\/tr><\/tbody><\/table><\/figure><h4 class=\"wp-block-heading\"> <\/h4><h4 class=\"wp-block-heading\">Part 3: Lambda Function with forEach<\/h4><h4 class=\"wp-block-heading\"> <\/h4><h5 class=\"wp-block-heading\">Lambda with forEach Example:<\/h5><h4 class=\"wp-block-heading\"> <\/h4><pre class=\"wp-block-code\"><code>List&lt;String&gt; fruits = Arrays.asList(\"Apple\", \"Banana\", \"Cherry\");\n\nfruits.forEach(fruit -&gt; System.out.println(fruit.toUpperCase()));\n<\/code><\/pre><h4 class=\"wp-block-heading\"> <\/h4><h4 class=\"wp-block-heading\">Iteration Analysis:<\/h4><h4 class=\"wp-block-heading\"> <\/h4><figure class=\"wp-block-table\"><table><thead><tr><th>Iteration<\/th><th>Explanation<\/th><th>Output<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Takes &#8220;Apple&#8221;, converts to uppercase.<\/td><td>Prints &#8220;APPLE&#8221;<\/td><\/tr><tr><td>2<\/td><td>Takes &#8220;Banana&#8221;, converts to uppercase.<\/td><td>Prints &#8220;BANANA&#8221;<\/td><\/tr><tr><td>3<\/td><td>Takes &#8220;Cherry&#8221;, converts to uppercase.<\/td><td>Prints &#8220;CHERRY&#8221;<\/td><\/tr><\/tbody><\/table><\/figure><h4 class=\"wp-block-heading\"> <\/h4><h4 class=\"wp-block-heading\">Part 4: Lambda Function that Returns a Value<\/h4><h4 class=\"wp-block-heading\"> <\/h4><h5 class=\"wp-block-heading\">Lambda Returning Value Example:<\/h5><h4 class=\"wp-block-heading\"> <\/h4><pre class=\"wp-block-code\"><code>import java.util.Arrays;\nimport java.util.List;\nimport java.util.stream.Collectors;\n\nList&lt;String&gt; words = Arrays.asList(\"hello\", \"world\");\nList&lt;String&gt; upperCaseWords = words.stream()\n                                   .map(word -&gt; word.toUpperCase())\n                                   .collect(Collectors.toList());\n<\/code><\/pre><h4 class=\"wp-block-heading\"> <\/h4><h5 class=\"wp-block-heading\">Iteration Analysis for <code>.map(word -&gt; word.toUpperCase())<\/code>:<\/h5><h4 class=\"wp-block-heading\"> <\/h4><figure class=\"wp-block-table\"><table><thead><tr><th>Iteration<\/th><th>Explanation<\/th><th>Output at This Step<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Takes &#8220;hello&#8221;, converts to uppercase.<\/td><td>&#8220;HELLO&#8221;<\/td><\/tr><tr><td>2<\/td><td>Takes &#8220;world&#8221;, converts to uppercase.<\/td><td>&#8220;WORLD&#8221;<\/td><\/tr><\/tbody><\/table><\/figure><h4 class=\"wp-block-heading\"> <\/h4><p>The final output, <code>upperCaseWords<\/code>, is a list containing [&#8220;HELLO&#8221;, &#8220;WORLD&#8221;].<\/p><h4 class=\"wp-block-heading\"> <\/h4><h5 class=\"wp-block-heading\">Detailed Explanation<\/h5><h4 class=\"wp-block-heading\"> <\/h4><p>When we use Java Streams combined with methods like <code>.map()<\/code> and <code>.collect()<\/code>, we are effectively performing loop-like operations without explicitly using traditional loop keywords (<code>for<\/code>, <code>while<\/code>, <code>do-while<\/code>). Here&#8217;s a simplified explanation:<\/p><h4 class=\"wp-block-heading\"> <\/h4><h5 class=\"wp-block-heading\">Looping with Streams and Methods:<\/h5><h4 class=\"wp-block-heading\"> <\/h4><ol class=\"wp-block-list\"><li><strong>Streaming<\/strong>: When we call <code>words.stream()<\/code>, we&#8217;re setting up a &#8216;stream&#8217; of elements from the <code>words<\/code> list. Think of a stream as a conveyor belt in a factory where each element (word) moves along the belt, one at a time, ready for processing.<\/li> <li><strong>Mapping<\/strong>: The <code>.map(word -&gt; word.toUpperCase())<\/code> is like having a worker along the conveyor belt who takes each word, changes it to uppercase, and then puts it back on the belt. We haven&#8217;t used a loop, but we have effectively &#8216;looped&#8217; over each element, transforming it.<\/li> <li><strong>Collecting<\/strong>: Finally, <code>.collect(Collectors.toList())<\/code> is like gathering all the processed items off the belt and packaging them into a new box (list). This step gathers all the transformed elements (now uppercase words) and puts them into a new list.<\/li><\/ol><h4 class=\"wp-block-heading\"> <\/h4><h5 class=\"wp-block-heading\">Why Use This Approach?<\/h5><h4 class=\"wp-block-heading\"> <\/h4><ul class=\"wp-block-list\"><li><strong>Clarity and Conciseness<\/strong>: This method is often clearer and more concise than traditional loops. It tells you exactly what&#8217;s happening: &#8220;stream these items, apply this transformation, and then collect the results.&#8221;<\/li> <li><strong>Functional Style<\/strong>: It promotes a functional programming style, which can lead to more readable and maintainable code.<\/li> <li><strong>Parallelization<\/strong>: Java Streams can easily be parallelized (just by changing <code>stream()<\/code> to <code>parallelStream()<\/code>) to improve performance, especially for large collections.<\/li><\/ul><h4 class=\"wp-block-heading\"> <\/h4><p>In summary, while we are not using explicit loop constructs, the operations on the stream (like <code>.map()<\/code> and <code>.collect()<\/code>) are implicitly &#8216;looping&#8217; through the elements, applying transformations, and collecting results. It&#8217;s a more abstract way of thinking about iterating over collections, emphasizing what you want to do rather than how to do it.<\/p><h4 class=\"wp-block-heading\"> <\/h4><p>\u00a0<\/p><h4 class=\"wp-block-heading\"><\/h4><p><\/p><p><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Lessons Lessons &nbsp; Setting Up Your Development Environment Java Basics &#8211; Syntax, Variables, Data Types, and Operators Understanding Objects and Classes in Java Understanding Encapsulation in Java Understanding Inheritance in Java: The &#8220;Is-A&#8221; Relationship Understanding Constructors in Java Inheritance Understanding Access Modifiers in Java Inheritance Understanding Polymorphism in Java Understanding Abstract Classes and Methods in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3335,"menu_order":12,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3418","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Understanding Loops in Java: forEach and lambda - Sankham Technologies<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Understanding Loops in Java: forEach and lambda - Sankham Technologies\" \/>\n<meta property=\"og:description\" content=\"Lessons Lessons &nbsp; Setting Up Your Development Environment Java Basics &#8211; Syntax, Variables, Data Types, and Operators Understanding Objects and Classes in Java Understanding Encapsulation in Java Understanding Inheritance in Java: The &#8220;Is-A&#8221; Relationship Understanding Constructors in Java Inheritance Understanding Access Modifiers in Java Inheritance Understanding Polymorphism in Java Understanding Abstract Classes and Methods in [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/\" \/>\n<meta property=\"og:site_name\" content=\"Sankham Technologies\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-15T17:04:43+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sankhamtech.com\\\/index.php\\\/content\\\/in\\\/en\\\/home\\\/free-courses\\\/understanding-object-oriented-programming-in-java\\\/understanding-loops-in-java-foreach-and-lambda\\\/\",\"url\":\"https:\\\/\\\/sankhamtech.com\\\/index.php\\\/content\\\/in\\\/en\\\/home\\\/free-courses\\\/understanding-object-oriented-programming-in-java\\\/understanding-loops-in-java-foreach-and-lambda\\\/\",\"name\":\"Understanding Loops in Java: forEach and lambda - Sankham Technologies\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sankhamtech.com\\\/#website\"},\"datePublished\":\"2024-11-15T17:04:03+00:00\",\"dateModified\":\"2024-11-15T17:04:43+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sankhamtech.com\\\/index.php\\\/content\\\/in\\\/en\\\/home\\\/free-courses\\\/understanding-object-oriented-programming-in-java\\\/understanding-loops-in-java-foreach-and-lambda\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sankhamtech.com\\\/index.php\\\/content\\\/in\\\/en\\\/home\\\/free-courses\\\/understanding-object-oriented-programming-in-java\\\/understanding-loops-in-java-foreach-and-lambda\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sankhamtech.com\\\/index.php\\\/content\\\/in\\\/en\\\/home\\\/free-courses\\\/understanding-object-oriented-programming-in-java\\\/understanding-loops-in-java-foreach-and-lambda\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sankhamtech.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Content\",\"item\":\"https:\\\/\\\/sankhamtech.com\\\/index.php\\\/content\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"India\",\"item\":\"https:\\\/\\\/sankhamtech.com\\\/index.php\\\/content\\\/in\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"English\",\"item\":\"https:\\\/\\\/sankhamtech.com\\\/index.php\\\/content\\\/in\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sankhamtech.com\\\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Free Courses\",\"item\":\"https:\\\/\\\/sankhamtech.com\\\/index.php\\\/content\\\/in\\\/en\\\/home\\\/free-courses\\\/\"},{\"@type\":\"ListItem\",\"position\":7,\"name\":\"Understanding Object-Oriented Programming in Java\",\"item\":\"https:\\\/\\\/sankhamtech.com\\\/indexphp\\\/content\\\/in\\\/en\\\/home\\\/free-courses\\\/understanding-object-oriented-programming-in-java\\\/\"},{\"@type\":\"ListItem\",\"position\":8,\"name\":\"Understanding Loops in Java: forEach and lambda\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/sankhamtech.com\\\/#website\",\"url\":\"https:\\\/\\\/sankhamtech.com\\\/\",\"name\":\"Sankham Technologies\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/sankhamtech.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/sankhamtech.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/sankhamtech.com\\\/#organization\",\"name\":\"Sankham Technologies\",\"url\":\"https:\\\/\\\/sankhamtech.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/sankhamtech.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/sankhamtech.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/Logo-Dark-1.png\",\"contentUrl\":\"https:\\\/\\\/sankhamtech.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/Logo-Dark-1.png\",\"width\":306,\"height\":74,\"caption\":\"Sankham Technologies\"},\"image\":{\"@id\":\"https:\\\/\\\/sankhamtech.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Understanding Loops in Java: forEach and lambda - Sankham Technologies","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:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/","og_locale":"en_US","og_type":"article","og_title":"Understanding Loops in Java: forEach and lambda - Sankham Technologies","og_description":"Lessons Lessons &nbsp; Setting Up Your Development Environment Java Basics &#8211; Syntax, Variables, Data Types, and Operators Understanding Objects and Classes in Java Understanding Encapsulation in Java Understanding Inheritance in Java: The &#8220;Is-A&#8221; Relationship Understanding Constructors in Java Inheritance Understanding Access Modifiers in Java Inheritance Understanding Polymorphism in Java Understanding Abstract Classes and Methods in [&hellip;]","og_url":"https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/","og_site_name":"Sankham Technologies","article_modified_time":"2024-11-15T17:04:43+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/","url":"https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/","name":"Understanding Loops in Java: forEach and lambda - Sankham Technologies","isPartOf":{"@id":"https:\/\/sankhamtech.com\/#website"},"datePublished":"2024-11-15T17:04:03+00:00","dateModified":"2024-11-15T17:04:43+00:00","breadcrumb":{"@id":"https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/understanding-loops-in-java-foreach-and-lambda\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sankhamtech.com\/"},{"@type":"ListItem","position":2,"name":"Content","item":"https:\/\/sankhamtech.com\/index.php\/content\/"},{"@type":"ListItem","position":3,"name":"India","item":"https:\/\/sankhamtech.com\/index.php\/content\/in\/"},{"@type":"ListItem","position":4,"name":"English","item":"https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/"},{"@type":"ListItem","position":5,"name":"Home","item":"https:\/\/sankhamtech.com\/"},{"@type":"ListItem","position":6,"name":"Free Courses","item":"https:\/\/sankhamtech.com\/index.php\/content\/in\/en\/home\/free-courses\/"},{"@type":"ListItem","position":7,"name":"Understanding Object-Oriented Programming in Java","item":"https:\/\/sankhamtech.com\/indexphp\/content\/in\/en\/home\/free-courses\/understanding-object-oriented-programming-in-java\/"},{"@type":"ListItem","position":8,"name":"Understanding Loops in Java: forEach and lambda"}]},{"@type":"WebSite","@id":"https:\/\/sankhamtech.com\/#website","url":"https:\/\/sankhamtech.com\/","name":"Sankham Technologies","description":"","publisher":{"@id":"https:\/\/sankhamtech.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sankhamtech.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/sankhamtech.com\/#organization","name":"Sankham Technologies","url":"https:\/\/sankhamtech.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sankhamtech.com\/#\/schema\/logo\/image\/","url":"https:\/\/sankhamtech.com\/wp-content\/uploads\/2023\/12\/Logo-Dark-1.png","contentUrl":"https:\/\/sankhamtech.com\/wp-content\/uploads\/2023\/12\/Logo-Dark-1.png","width":306,"height":74,"caption":"Sankham Technologies"},"image":{"@id":"https:\/\/sankhamtech.com\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/sankhamtech.com\/index.php\/wp-json\/wp\/v2\/pages\/3418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sankhamtech.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sankhamtech.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sankhamtech.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sankhamtech.com\/index.php\/wp-json\/wp\/v2\/comments?post=3418"}],"version-history":[{"count":4,"href":"https:\/\/sankhamtech.com\/index.php\/wp-json\/wp\/v2\/pages\/3418\/revisions"}],"predecessor-version":[{"id":3422,"href":"https:\/\/sankhamtech.com\/index.php\/wp-json\/wp\/v2\/pages\/3418\/revisions\/3422"}],"up":[{"embeddable":true,"href":"https:\/\/sankhamtech.com\/index.php\/wp-json\/wp\/v2\/pages\/3335"}],"wp:attachment":[{"href":"https:\/\/sankhamtech.com\/index.php\/wp-json\/wp\/v2\/media?parent=3418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}