How to Check Palindrome with Java Streams

Java Practice — Palindrome Check Using Streams Today I revisited a small but powerful problem: checking if a string is a palindrome — this time using Java Streams for a more functional approach. Here’s the snippet I practiced: import java.util.stream.IntStream; public class PalindromeWithStreams {   public static void main(String[] args) {     String s = "madam";          boolean isPalindrome = IntStream.range(0, s.length() / 2)         .allMatch(i -> s.charAt(i) == s.charAt(s.length() - i - 1));     System.out.println(isPalindrome ? "Palindrome" : "Not palindrome");   } } > Key takeaway: 1: IntStream.range(0, s.length() / 2) generates indices for only half the string. 2: .allMatch() ensures every pair of characters (from front and back) are equal. 3: Clean, concise, and expressive — a great example of functional programming in modern Java. #Java #Streams #CodingPractice #ProblemSolving #CleanCode #DevelopersJourney

Tq Gopi V . This is very helpful to interview prospective.

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories