👇 🚀 Stream API Coding – 1: Check if a String is Palindrome Exploring the power of Java 8 Stream API with a simple yet elegant example — checking whether a string is a palindrome using functional style. 💡 String s = "racecar"; boolean isPalindrome = IntStream.range(0, s.length() / 2) .allMatch(i -> s.charAt(i) == s.charAt(s.length() - i - 1)); System.out.println(isPalindrome ? "String is Palindrome" : "String is not palindrome"); ✨ Key Learnings: ✅ Use IntStream.range() for index-based iteration ✅ allMatch() ensures all comparisons pass ✅ Clean and concise approach — no loops, no extra variables 📚 Output: 👉 String is Palindrome This is just the beginning — more Stream API challenges coming soon! 🔥 #Java #StreamAPI #CodingChallenge #JavaDeveloper #FunctionalProgramming #CleanCode #CodingSeries #InterviewPreparation
Gajanan Gaikwad’s Post
More Relevant Posts
-
🚀 Stream API Coding – 1: Check if a String is Palindrome Exploring the power of Java 8 Stream API with a simple yet elegant example — checking whether a string is a palindrome using functional style. 💡 String s = "racecar"; boolean isPalindrome = IntStream.range(0, s.length() / 2) .allMatch(i -> s.charAt(i) == s.charAt(s.length() - i - 1)); System.out.println(isPalindrome ? "String is Palindrome" : "String is not palindrome"); ✨ Key Learnings: ✅ Use IntStream.range() for index-based iteration ✅ allMatch() ensures all comparisons pass ✅ Clean and concise approach — no loops, no extra variables 📚 Output: 👉 String is Palindrome This is just the beginning — more Stream API challenges coming soon! 🔥 #Java #StreamAPI #CodingChallenge #JavaDeveloper #FunctionalProgramming #CleanCode #CodingSeries #InterviewPreparation
To view or add a comment, sign in
-
Day 89 of #100DaysOfCode Solved Find Numbers with Even Number of Digits in Java 🔢 Approach The goal of this problem was to count how many integers in a given array have an even number of digits. I implemented two methods: findNumbers(int[] nums): This is the main function that iterates through every number in the input array nums. isEvenOrOdd(int n): This helper function takes an integer and determines if its digit count is even or odd. Inside the helper function, I used a while loop to count the digits: I initialized a count to 0. The loop continues as long as $n > 0$. In each iteration, I increment count and then perform integer division by 10 (n = n / 10) to remove the least significant digit. Finally, I return true if the total count of digits is even (count \% 2 == 0). This efficient, digit-by-digit checking approach resulted in a strong performance, beating 98.90% of other submissions. #Java #100DaysOfCode #LeetCode #CodingChallenge #Algorithms #Array #ProblemSolving #Optimization
To view or add a comment, sign in
-
-
🧠 Java Stream API: When do you need .mapToInt()? I hit this bug recently while dry-running some stream logic: List<Integer> intValues = IntStream.range(0, 11).boxed().toList(); int sum = IntStream.range(0, 11).sum(); // ✅ Works But then I tried this: List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); int sum1 = numbers.stream().sum(); // ❌ Doesn't compile! Wait — both are List<Integer>. Why does one need .mapToInt() and the other doesn’t? 🔍 The Difference Stream Type Can use .sum() / .min() directly? Why IntStream ✅ Yes Primitive stream with numeric ops Stream<Integer> ❌ No Object stream — needs conversion So when you start with boxed types (List<Integer>), you must use .mapToInt() to convert to IntStream before calling numeric operations like .sum(), .min(), or .average(). ✅ Correct Usage int sum = numbers.stream() .mapToInt(Integer::intValue) .sum(); int min = numbers.stream() .mapToInt(Integer::intValue) .min() .orElse(Integer.MAX_VALUE); 💡 Pro Tip: If you're already working with IntStream, skip the boxing — it's faster and cleaner: int sum = IntStream.range(0, 11).sum(); 🧪 I turned this into a dry-run checklist for my team — because even seasoned devs trip over this. If you’ve got a mental model or trick to remember this, drop it in the comments! #JavaTips #StreamAPI #InterviewPrep #CodeCraft #DineshDebugs #FunctionalProgramming #DryRunReady
To view or add a comment, sign in
-
Day 46 of #100DaysOfLeetCode Challenge 🚀Today’s Problem: Remove Duplicate Letters (LeetCode - Medium) Language: Java In this problem, the goal is to remove duplicate letters from a string such that every letter appears once and the result is the smallest lexicographical order possible. Concepts Covered: Stack for maintaining order Greedy approach for smallest lexicographical sequence Tracking last occurrence index of each character Boolean array to keep track of visited characters Key Takeaways: Understanding when to remove elements from the stack is crucial for optimal ordering. The combination of stack + greedy ensures both uniqueness and lexicographical minimality. #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingChallenge #DSA #DevelopersJourney
To view or add a comment, sign in
-
-
💻 LeetCode Challenge – Day 5: String to Integer (atoi) Today's problem was all about converting a string into an integer — seems simple, but the edge cases make it tricky! 🧠 🔹 Problem: Implement the atoi function, which converts a string to a 32-bit signed integer (just like in C/C++). 🔹 Key Learnings: ✅ Handling whitespaces and optional '+' or '-' signs ✅ Managing non-digit characters gracefully ✅ Preventing integer overflow & underflow ✅ Importance of clean parsing logic This problem really improved my understanding of string manipulation and boundary conditions in Java. 🚀 #LeetCode #100DaysOfCode #Java #CodingChallenge #ProblemSolving #StringToInteger #CodingJourney
To view or add a comment, sign in
-
-
🚀Day 97/100 #100DaysOfLeetCode 👩💻Problem: Valid Square✅ 💻Language: Java 💡Approach: To check if four given points form a valid square, I calculated all six pairwise distances between the points. 🔹A valid square must have two distinct distances — 4 equal smaller sides and 2 equal longer diagonals. 🔹Used a HashMap to count occurrences of each distance. 🔹If the map has exactly two distinct non-zero distances and the smaller one appears 4 times while the larger appears 2 times, it’s a square! 🧠Key Takeaways: 🔹Strengthened understanding of geometry-based problems. 🔹Reinforced hashing techniques for quick frequency checks. 🔹Improved logic for pairwise comparison and distance calculation. ⚙️Performance: ⏱️Runtime: 2 ms (Beats 27.27%) 💾Memory: 41.91 MB (Beats 22.03%) #100DaysOfLeetCode #Java #CodingChallenge #LeetCode #ProblemSolving #CodingChallenge
To view or add a comment, sign in
-
-
Another late-night success Solved a tricky binary search + sliding window problem efficiently in Java, optimizing power distribution logic in minimal runtime. 📊 Runtime: 31 ms 💡 Beats 89.29% of Java submissions 🧩 Concepts used: Binary Search, Prefix Sum, Sliding Window Each accepted solution reminds me that writing clean, efficient code isn’t just about passing tests — it’s about thinking like the system itself. #Java #LeetCode #ProblemSolving #Algorithms #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 5 — The “Polymorphism Trap” That Even 5+ Year Devs Fall Into 😵💫 Everyone thinks they know Polymorphism… Until Overloading and Overriding collide inside the same class 🔥 class Parent { void calc(Number n) { System.out.println("Parent Number"); } void calc(Integer i) { System.out.println("Parent Integer"); } } class Child extends Parent { @Override void calc(Number n) { System.out.println("Child Number"); } } public class PolymorphPuzzle { public static void main(String[] args) { Parent p = new Child(); p.calc(null); } } 💭 Question: What will be the output? 1️⃣ Parent Number 2️⃣ Parent Integer 3️⃣ Child Number 4️⃣ Compile-time Error 💬 Drop your answer in the comments 👇 90% developers get this wrong — can you get it right without running the code? 😎 Let’s see who’s the real Java champ 🧠🔥 #Java #Polymorphism #CodingChallenge #SpringBoot #InterviewQuestion #Day5Challenge #JavaDeveloper #LearnJava #OOPsConcepts
To view or add a comment, sign in
-
Day 24 of #50DaysOfCode – Java 💻 Today’s challenge was to check whether a number is an Automorphic Number. An Automorphic Number is a number whose square ends with the same digits as the number itself. Examples: 5 → 25 ✔️ (ends with 5) 76 → 5776 ✔️ (ends with 76) This problem helped me understand digit comparison, modulus operations, and number patterns in Java 🔍✨ #Java #CodingChallenge #50DaysOfCode #LearnToCode #ProgrammingBasics #LogicBuilding #CodeDaily #ProblemSolving #AutomorphicNumber #JavaBeginner
To view or add a comment, sign in
-
Day 15: Covariant Return Type in Java In Java inheritance, we can't change the return type when overriding a method, but there's an exception called covariant return type. This means we can change the return type to a subtype of the original one (only for non-static methods). What's happening here? The parent class A defines a car() method that returns a P object. The subclass B overrides car() and changes the return type to Q, which is a subclass of P. This is allowed because Q is a covariant return type of P. Why does this matter? This allows you to return a more specific type in the subclass without breaking the contract of the parent method. It gives you more flexibility in your code. 10000 Coders #Java #Inheritance #LearningJourney #JavaDeveloper #Day15 #SoftwareDevelopment #LearningEveryday
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development