{"id":23585149,"url":"https://github.com/chaseofthejungle/java-lambda-guide","last_synced_at":"2026-01-24T23:33:26.642Z","repository":{"id":269739491,"uuid":"908070956","full_name":"chaseofthejungle/java-lambda-guide","owner":"chaseofthejungle","description":"An overview of Java Lambda expressions and their power.","archived":false,"fork":false,"pushed_at":"2025-06-24T16:31:05.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-24T17:41:23.185Z","etag":null,"topics":["java-lambda","lambda","lambda-expressions"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chaseofthejungle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-25T03:40:44.000Z","updated_at":"2025-06-24T16:31:08.000Z","dependencies_parsed_at":"2025-04-03T04:23:28.768Z","dependency_job_id":null,"html_url":"https://github.com/chaseofthejungle/java-lambda-guide","commit_stats":null,"previous_names":["chaseofthejungle/java-lambda-guide"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chaseofthejungle/java-lambda-guide","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaseofthejungle%2Fjava-lambda-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaseofthejungle%2Fjava-lambda-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaseofthejungle%2Fjava-lambda-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaseofthejungle%2Fjava-lambda-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chaseofthejungle","download_url":"https://codeload.github.com/chaseofthejungle/java-lambda-guide/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaseofthejungle%2Fjava-lambda-guide/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28739002,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-24T22:12:27.248Z","status":"ssl_error","status_checked_at":"2026-01-24T22:12:10.529Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java-lambda","lambda","lambda-expressions"],"created_at":"2024-12-27T03:14:09.571Z","updated_at":"2026-01-24T23:33:26.627Z","avatar_url":"https://github.com/chaseofthejungle.png","language":null,"readme":"# Java Lambda Expressions Guide\n\n**Definition/Overview:** Starting with Java 8, *lambda expressions* have provided parameter acceptance and value returning in a readable/concise and powerful manner.\n\n#### Table of Contents\n  \n1. [Java Lambda Syntax](#lambda-syntax)\n2. [Three Reasons to Use Lambdas](#lambda-reasons)\n3. [Code Examples](#code-examples)\n3. [Supplemental Resources](#supplemental)\n  \n## 1. \u003ca name=\"lambda-syntax\"\u003eJava Lambda Syntax\u003c/a\u003e\n  \nSingle parameter: `parameter -\u003e expression`  \nMultiple parameters: `(parameter1, parameter2) -\u003e expression`  \nFor advanced features (e.g., return value, variables, conditions): `(parameter1, parameter2) -\u003e { block of code }`\n\nA simple demonstration of a multi-parameter lambda:\n  \n`(a, b) -\u003e a + b`\n  \n'a' and 'b' are parameters in the above example, and a + b is an expression.  \n\nAlthough the use of lambdas may be unnecessary for simple operations, they are especially powerful when it comes to more complicated tasks (e.g., data transformation, event handling, sorting, filtering, concurrency, collections tasks).\n  \n\u003chr /\u003e\n  \n## 2. \u003ca name=\"lambda-reasons\"\u003eThree Reasons to Use Lambdas\u003c/a\u003e\n  \n* **Functional Programming Support**\n  + Use of higher-order functions (e.g., filter(), map()) and other functional programming patterns make code modular and maintainable.\n* **Highly Readable**\n  + Use of shortened, succinct parameter and expression syntax to provide abstraction for redundant operations.\n    - Likewise: no need for anonymous classes.\n* **Parallel Processing**\n  + Lambda expressions (in tandem with Stream API) allow collections to be parallel processed, potentially increasing performance.\n  \n\u003chr /\u003e\n\n## 3. \u003ca name=\"code-examples\"\u003eCode Examples\u003c/a\u003e\n  \n**With a Runnable Interface Inner Class:**\n  \n```\nRunnable run1 = new Runnable() {\n    @Override\n    public void run() {\n        System.out.println(\"Task #1 is executing...\");\n    }\n};\n\n// The actual lambda expression\nRunnable run2 = () -\u003e {\n    System.out.println(\"Task #2 is executing...\");\n};\n```\n  \n**Filtering Stream Results:**\n  \n```\nList\u003cInteger\u003e vals = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7);\n\nvals.stream()\n       .filter(n -\u003e n % 2 == 1) // odd values only\n       .forEach(n -\u003e System.out.println(n));\n```\n  \n**Sorting a List of Strings:**\n  \n```\nList\u003cString\u003e fruit = Arrays.asList(\"Banana\", \"Watermelon\", \"Lime\", \"Mango\");\n\nCollections.sort(fruit, new Comparator\u003cString\u003e() {\n    @Override\n    public int compare(String a, String b) {\n        return a.compareTo(b);\n    }\n});\n\nCollections.sort(fruit, (a, b) -\u003e a.compareTo(b)); // sorting via lambda\nSystem.out.println(fruit);\n```\n  \n**Handling a GUI Button Click Event:**\n  \nThe following JavaFX code can be simplified...\n\n```\nButton button = new Button(\"Submit Form\");\nbutton.setOnAction(new EventHandler \u003cActionEvent\u003e() {\n    @Override\n    public void handle(ActionEvent event) {\n        System.out.println(\"Thank you for your submission!\");\n    }\n});\n```\n\n... using a lambda.\n\n```\nButton button = new Button(\"Submit Form\");\nbutton.setOnAction(event -\u003e System.out.println(\"Thank you for your submission!\"));\n```\n  \n**Sorting Items by Price in an e-Commerce Shop:**\n  \nThe following code can be simplified...\n  \n```\nList\u003cItem\u003e items = Arrays.asList(\n    new Item(\"CD\", 1600),\n    new Item(\"Vinyl\", 2200),\n    new Item(\"MP3\", 1400)\n);\n\nCollections.sort(items, new Comparator\u003cItem\u003e() {\n    @Override\n    public int compare(Item item1, Item item2) {\n        return Integer.compare(item1.getPrice(), item2.getPrice());\n    }\n});\n```\n  \n... using a lambda.\n  \n```\nList\u003cItem\u003e items = Arrays.asList(\n    new Item(\"CD\", 1600),\n    new Item(\"Vinyl\", 2200),\n    new Item(\"MP3\", 1400)\n);\n\nitems.sort((item1, item2) -\u003e Integer.compare(item1.getPrice(), item2.getPrice()));\n```\n  \n\u003chr /\u003e\n  \n## 4. \u003ca name=\"supplemental\"\u003eSupplemental Resources\u003c/a\u003e\n  \n* *[Java Data Structure Leetcode Interview Questions](https://github.com/chaseofthejungle/java-data-structure-leetcode-interview-questions)*\n* *[Java Quick Reference Guide](https://github.com/chaseofthejungle/java-quick-reference-guide)*\n* *[Official Amazon Documentation on AWS's Lambdas](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html)*\n  \n\u003chr /\u003e\n  \n**TODO:** Add a code example for filtering and mapping.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaseofthejungle%2Fjava-lambda-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchaseofthejungle%2Fjava-lambda-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaseofthejungle%2Fjava-lambda-guide/lists"}