Introduction
A palindrome is a word, phrase, number, or other sequences of characters that reads the same forward and backward (ignoring spaces, punctuation, and capitalization). Finding palindromic sub-strings within a given string is a fascinating problem and has applications in various domains including bioinformatics and text processing.

In this article, we will explore a Java program that finds all palindromic sub-strings of a given string.
Read More, addition of two numbers in java
Understanding Palindromes
Before diving into the code, let's understand what a palindrome is. A palindrome is a sequence of characters that reads the same backward as forward. For example, "madam" or "racecar" are palindromes.
Also read palindrome number in python.
Approach to Find Palindromic Sub-Strings
We can approach this problem using the following steps:
-
Iterate Through the String: We'll need to go through each character of the string.
-
Expand Around the Center: For every character, we'll expand around it and check if the characters are the same on both sides.
- Count and Store: If it's a palindrome, we count and store it.
Here's the complete Java code to find all palindromic sub-strings of a given string:
This code will output:
Palindromic sub-strings are:
m
a
d
ada
madam
a
m

Also check, Palindrome string
Detailed Explanation
Loop through Each Character: The outer loop for (int center = 0; center <= 2 * input.length() - 1; center++) iterates through each character, and for each character, it treats it as a center.
Expand Around Center: The inner loop while (left >= 0 && right < input.length() && input.charAt(left) == input.charAt(right)) expands around the center. If the characters at the left and right are equal, it's part of a palindrome.
Print the Palindrome: Inside the inner loop, we print the palindrome using input.substring(left, right + 1).
Time Complexity
The time complexity of this approach is O(n2) where
n is the length of the string. This is because, in the worst case, we may end up checking
n characters around each center.
Also see, Java Ioexception and Eclipse ide for Java Developers