Java Streams for Efficient Problem Solving

Day 17 — #100DaysJava today I learned Stream API in Java.  Today I practiced DSA problems using Java Streams + optimized approaches. Not just solving problems — understanding how to solve them better. 1> Key Learning: Streams make code clean, but not always fast. Choosing the right approach matters more than writing one-liners. Q. Problems I worked on: 1 Two Sum → HashSet (O(n)) 2 Longest Consecutive → Set (optimized) 3 Move Zeros → Loop + Stream 4 Find Duplicates → Set trick 5 Majority Element → Boyer-Moore 6 Kth Largest → sorting + skip() 7 Subarray Sum = K → prefix sum (important) ** Some simple stream examples I used:** Q. Even → double → collect List<Integer> result = Arrays.stream(arr) .filter(n -> n % 2 == 0) .map(n -> n * 2) .boxed() .collect(Collectors.toList()); Q. Find duplicates Set<Integer> seen = new HashSet<>(); List<Integer> dup = Arrays.stream(arr) .filter(n -> !seen.add(n)) .boxed() .collect(Collectors.toList()); Q. Remove duplicates List<Integer> unique = Arrays.stream(arr) .distinct() .boxed() .collect(Collectors.toList()); Writing clean + efficient code > just making it work Day by day — improving consistency and thinking. 💪 If you’re learning DSA or Java, let’s connect 👇 Are you using Streams in your daily Java work? What is the most useful stream operation you use? Drop it below! 🙏 17 days in. Every day something new clicks. 💪 Day 1 ...................................... Day 17 #Java hashtag #StreamAPI hashtag #FunctionalProgramming hashtag #100DaysOfJava hashtag #JavaDeveloper hashtag #LearningInPublic hashtag #BackendDevelopment hashtag #100DaysOfCode hashtag #CleanCode hashtag #ModernJava

To view or add a comment, sign in

Explore content categories