Java Program to Find All Palindromic Sub-Strings of a String Last Updated : 03 Aug, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a string, the task is to count all palindrome substring in a given string. Input : aba Output : 4 Explanation : All palindrome substring are : "aba" , "a" , "b", "a" Input : TENET Output : 7 Explanation : All palindrome sub-string are : "T" , "E" , "N", "E", "T" , "ENE" , "TENET" Approach: Take the substrings from the given string.Now check whether the substring is Palindrome or not.If the substring is Palindrome increment the count by 1 else if not count is not incremented.Return the count as it represents the number of substrings.Print and display on the console. Example: Java // Java Program to Find all palindromic sub-strings // of a given string // Importing input output classes import java.io.*; // Main class // To check for palindromic sub-strings public class GFG { // Method 1 // To check for substring public static boolean check(String subS) { int size = subS.length(); // Iterating over string till midway to // check palindromic behavior for (int i = 0; i < size / 2; i++) { if (subS.charAt(i) != subS.charAt(size - i - 1)) { // Non-palindromic behavior return false; } } // Palindromic behavior return true; } // Method 2 // Main driver method public static void main(String[] args) { // Custom input string String str = "MALAYALAM"; int count = 0; // Outer loop iterating over input string for (int i = 0; i < str.length(); i++) { // Inner loop iterating from current starting // character of outer loop current starting // character for (int j = i; j < str.length(); j++) { // Getting the substrings String subString = str.substring(i, j + 1); // Checking whether the substring is // palindrome if (check(subString)) { // Increment the count only if // substring is palindrome count++; } } } // Print and display the number of substrings that // are palindromic System.out.println( "No.of palindromic substrings in the given string are " + count); } } OutputNo.of palindromic substrings in the given string are 15 Comment More infoAdvertise with us Next Article Maximum even length sub-string that is permutation of a palindrome G ganiprabhakar Follow Improve Article Tags : Java Java Programs Java-String-Programs Practice Tags : Java Similar Reads Find all palindromic sub-strings of a given string | Set 2 Given a string, the task is to find all the palindromic sub-strings from the given string.In Set - 1, another approach has been already discussed and that consider only distinct sub-strings but in this equal sub-strings i.e. ll and ll are considered as two sub-strings, not one. Examples: Input : hel 7 min read Java Program to Check Whether a String is a Palindrome A string in Java can be called a palindrome if we read it from forward or backward, it appears the same or in other words, we can say if we reverse a string and it is identical to the original string for example we have a string s = "jahaj " and when we reverse it s = "jahaj"(reversed) so they look 8 min read Java Program To Check If A Linked List Of Strings Forms A Palindrome Given a linked list handling string data, check to see whether data is palindrome or not? Examples: Input: a -> bc -> d -> dcb -> a -> NULL Output: True String "abcddcba" is palindrome. Input: a -> bc -> d -> ba -> NULL Output: False String "abcdba" is not palindrome. Reco 2 min read Java Program to Print Smallest and Biggest Possible Palindrome Word in a Given String A Palindrome String is a string whose reversed string is equal to the original string. In this Java Program, we are going to see the approach of printing the smallest and biggest palindrome word in a String. Given a sentence of words in the form of a string, and we need to print the smallest and lon 3 min read Maximum even length sub-string that is permutation of a palindrome Given string str , the task is to find the maximum length of the sub-string of str that can be arranged into a Palindrome (i.e at least one of its permutation is a Palindrome). Note that the sub-string must be of even length. Examples: Input: str = "124565463" Output: 6 "456546" is the valid sub-str 9 min read Return a Palindromic String after removing minimum length Prefix from given String Given a string B, the task is to find the minimum length prefix of the string which, when removed and added to the end of the string, will make the string a palindrome. Return the palindromic string. If no such string exists, we need to determine that. Examples: Input: "aabb"Output: "abba"Explanatio 5 min read Like