Skip to main content

Command Palette

Search for a command to run...

Lambda Expressions & Stream API in Java 8

Published
โ€ข2 min readโ€ขView as Markdown
A

๐Ÿ‘‹Hello! I'm ๐—”๐—ฑ๐—ถ๐˜๐˜†๐—ฎ ๐—ฃ๐—ฎ๐˜๐—ฒ๐—ฟ๐—ถ๐˜†๐—ฎ, a Computer Science Engineering graduate with a strong foundation in software development, data structures, and emerging technologies. I am actively seeking opportunities where I can contribute to impactful projects, deepen my technical expertise, and collaborate within a growth-oriented team environment. With hands-on experience in full-stack web development (MERN stack) and a growing interest in machine learning, I enjoy building scalable, user-focused applications and solving real-world challenges through clean, efficient code. ๐Ÿ’ผ ๐“๐ž๐œ๐ก๐ง๐ข๐œ๐š๐ฅ ๐๐ซ๐จ๐Ÿ๐ข๐œ๐ข๐ž๐ง๐œ๐ข๐ž๐ฌ โ†ฆ Languages: C++, Java, JavaScript โ†ฆ Web Development: MongoDB, Express.js, React, Node.js (MERN) โ†ฆ Tools & Frameworks: Git, GitHub, Tailwind CSS, REST APIs โ†ฆ Concepts: Object-Oriented Programming, Data Structures & Algorithms, Software Engineering Principles โ†ฆ Additional: Basic understanding of Cloud Services (AWS), CI/CD workflows, and version control ๐Ÿš€ ๐Š๐ž๐ฒ ๐’๐ญ๐ซ๐ž๐ง๐ ๐ญ๐ก๐ฌ โ†ฆ Adaptability: Quick to learn and apply new technologies and frameworks โ†ฆ Problem Solving: Strong grasp of DSA and algorithmic thinking through consistent practice โ†ฆ Project-Oriented Mindset: Experience building and deploying end-to-end applications โ†ฆ Collaboration: Comfortable working in teams, receiving feedback, and contributing to shared goals ๐ŸŒฑ ๐๐ž๐ฒ๐จ๐ง๐ ๐“๐ž๐œ๐ก Outside the digital world, I enjoy exploring the outdoors through ๐˜๐—ฟ๐—ฎ๐˜ƒ๐—ฒ๐—น๐—น๐—ถ๐—ป๐—ด, playing games like ๐—ฐ๐—ต๐—ฒ๐˜€๐˜€ and ๐—น๐—ถ๐˜€๐˜๐—ฒ๐—ป๐—ถ๐—ป๐—ด ๐—ฑ๐—ผ๐—ฐ๐˜‚๐—บ๐—ฒ๐—ป๐˜๐—ฎ๐—ฟ๐—ถ๐—ฒ๐˜€. These experiences enhance my creativity, focus, and resilienceโ€”qualities I bring to every project I undertake. ๐Ÿค ๐‹๐ž๐ญโ€™๐ฌ ๐‚๐จ๐ง๐ง๐ž๐œ๐ญ I am eager to contribute, learn, and grow alongside forward-thinking professionals. โ€‹๐Ÿ‡ซโ€‹๐Ÿ‡ชโ€‹๐Ÿ‡ชโ€‹๐Ÿ‡ฑโ€‹ โ€‹๐Ÿ‡ซโ€‹๐Ÿ‡ทโ€‹๐Ÿ‡ชโ€‹๐Ÿ‡ชโ€‹ โ€‹๐Ÿ‡นโ€‹๐Ÿ‡ดโ€‹ โ€‹๐Ÿ‡จโ€‹๐Ÿ‡ดโ€‹๐Ÿ‡ณโ€‹๐Ÿ‡ณโ€‹๐Ÿ‡ชโ€‹๐Ÿ‡จโ€‹๐Ÿ‡นโ€‹ โ€‹๐Ÿ‡ดโ€‹๐Ÿ‡ทโ€‹ โ€‹๐Ÿ‡ทโ€‹๐Ÿ‡ชโ€‹๐Ÿ‡ฆโ€‹๐Ÿ‡จโ€‹๐Ÿ‡ญโ€‹ โ€‹๐Ÿ‡ดโ€‹๐Ÿ‡บโ€‹๐Ÿ‡นโ€‹ โ€‹๐Ÿ‡ซโ€‹๐Ÿ‡ดโ€‹๐Ÿ‡ทโ€‹ - โ†ฆ Internship or job opportunities โ†ฆ Project collaborations โ†ฆ Knowledge sharing or mentorship ๐Ÿ“ง ๐„๐ฆ๐š๐ข๐ฅ: adityapateriya7986@gmail.com ๐ŸŒ ๐๐จ๐ซ๐ญ๐Ÿ๐จ๐ฅ๐ข๐จ ๐‹๐ข๐ง๐ค: https://aditya-pateriya-portfolio.vercel.app/

This week, I focused on two important Java 8 features: Lambda Expressions and the Stream API. Both are designed to make code cleaner, more readable, and more functional.

๐Ÿ”น Lambda Expressions

Before Java 8, overriding a single abstract method often meant writing anonymous inner classes. With lambdas, this becomes concise.

Example:

Phone p = no -> {
    System.out.println("Calling... " + no);
};
p.call(8888);

Key Learnings:

  • Works with functional interfaces (only one abstract method).

  • Syntax can be:

    • () -> { ... } (no argument)

    • (int x) -> { ... } (typed argument)

    • (x) -> { ... } (inferred type)

    • x -> { ... } (single argument, no parentheses)

๐Ÿ”น Stream API

Streams let us process collections in a functional, pipeline-based style. Instead of manually looping, checking conditions, and storing results, Streams let us write expressive code.

Example: Filtering Products

Without Streams:

List<Product> filtered = new ArrayList<>();
for(Product p : getProducts()) {
    if(p.price > 1000)
        filtered.add(p);
}

With Streams:

List<Product> filtered = getProducts()
                           .stream()
                           .filter(p -> p.price > 1000)
                           .collect(Collectors.toList());

โšก Challenge: Understanding How Streams Work Behind the Scenes

At first, just writing .stream().filter(...) didnโ€™t help me understand what was really happening. It felt like a black box.

After digging deeper, I realized:

  1. Collection to Stream โ†’ .stream() doesnโ€™t copy the data; it creates a pipeline view of the collection.

  2. Intermediate Operations (like .filter()) โ†’ applied lazily, meaning they donโ€™t execute immediately. They set up a โ€œrecipeโ€ for processing.

  3. Terminal Operation (like .collect()) โ†’ triggers the actual processing. At this point, each element flows through the pipeline, the condition is checked, and matching elements are collected into the new list.

So, Streams arenโ€™t magic. Theyโ€™re pipelines where data flows step by step until the terminal operation โ€œpullsโ€ results out.

๐ŸŒŸ Takeaway

  • Lambda Expressions simplify method implementations.

  • Stream API simplifies collection processing using pipelines.

  • Together, they make Java more expressive, readable, and modern.

What looked like โ€œone line of codeโ€ at first now makes sense - Streams provide a structured way of handling data, with clear stages of processing.

๐Ÿ“– Iโ€™ll continue sharing my journey every week. You can also read my previous blogs where Iโ€™ve shared my learnings, challenges, and solutions โ€“ hope they help you too!