SUBODH KUMAR’s Post

Day 16 — #100DaysJava today I learned Stream API in Java. And honestly, this one changed how I write code. ☕ Before streams, I used to write for loops for everything. Filter this, transform that, add them up. Five lines of code for something simple. Streams do the same thing in one line. Clean, readable, powerful. Here is what clicked for me today — saving this for anyone learning Java --- What is a Stream? A Stream is a pipeline. You take data, pass it through a series of operations, and get a result at the end. You are not changing the original data. You are just processing it. Think of it like a factory assembly line. Raw material goes in. Each station does one job. Final product comes out. --- The three operations I practiced today: filter() — keep only the elements that match a condition. I used it to get only even numbers from an array. Arrays.stream(arr).filter(n -> n % 2 == 0) map() — transform every element. I used it to double every number in the array. Arrays.stream(arr).map(n -> n * 2) reduce() — combine everything into one result. I used it to calculate the sum of all numbers. Arrays.stream(arr).reduce(0, (a, b) -> a + b) --- One thing that confused me first — boxed(). When you have an int array, Java creates an IntStream not a Stream of Integer objects. boxed() converts it from primitive int to Integer object so you can collect it into a List. IntStream → boxed() → Stream of Integer → collect to List Once I understood that, everything made sense. --- collect(Collectors.toList()) is how you end the stream and get your result back as a List. The stream itself does not store data — it just processes it. collect() is what actually creates the final collection. --- The real power of Streams — you can chain all of this together. Filter the evens, double them, collect into a list. One line. No loop. No temporary variables. This is exactly how modern Java code looks in real companies. --- 16 days in. Every day something new clicks. 💪 Day 1 ...................................... Day 16 Are you using Streams in your daily Java work? What is the most useful stream operation you use? Drop it below! 🙏 #Java #StreamAPI #FunctionalProgramming #100DaysOfJava #JavaDeveloper #LearningInPublic #BackendDevelopment #100DaysOfCode #CleanCode #ModernJava

To view or add a comment, sign in

Explore content categories