Saturday, July 13, 2019

Find Palindrome Strings in an Array Using Java


In this article, we will see how to find all palindrome strings from an array. This is a very frequently asked questions in interview.  Also there is a question to find all palindrome number from an array.  Find few more collection interview question.  

PalindromeStrings.java

package com.techbyteslearn.lab.basic;

/**
 * This program illustrates how to find palindrome strings from an array.
 */
public class PalindromeStrings {

    public static void main(String[] args) {
        String[] stringArray = {
            "eye",
            "jdg",
            "javadevelopersguide",
            "aabaa",
            "hello",
            "pip"
        };

        for (int i = 0; i < stringArray.length; i++) {
            printOnlyPalindrome(stringArray[i]);
        }
    }

    private static void printOnlyPalindrome(String str) {
        String oldString = str;
        StringBuilder builder = new StringBuilder(str);

        if (builder.reverse().toString().equals(oldString)) {
            System.out.println(oldString + " is a Palindrome String.");
        }
    }
}

Output:

eye is a Palindrome String.
aabaa is a Palindrome String.
pip is a Palindrome String.
Happy Learning.

13 comments:

  1. Greetings! Very helpful article! I came across many new ideas through this article. Thanks for sharing! Java Training in Bangalore is the best place to learn Java and Advanced Java and give you more practical knowledge.

    ReplyDelete
  2. indiantrendingblogAugust 8, 2019 at 4:24 PM

    Thanks For Sharing his nice post. Read Our Article in Fitness And Health Releted.
    web Development Company in Surat

    ReplyDelete
  3. Hi, Really Awesome post, Thanks for writing.
    Java Training in Delhi

    ReplyDelete
  4. Thank for foe explaining palindrome program thanks for your efforts angular certification

    ReplyDelete
  5. This is really a helpful blog I am really impressed with your work, keep it up the good work
    1Z0-819: Oracle Java SE 11 Developer
    1Z0-900: Java EE 7 Application Developer

    ReplyDelete
  6. thanks for sharing a valid information a useful blog posting .

    German Language Course In Chandigarh

    ReplyDelete
  7. Really awesome blog. Useful information and knowledge. Thanks for posting this blog. Keep sharing more blogs again soon.
    UI Development Institute in Hyderabad
    RPA Training Institute in Hyderabad
    Python Training Institute in Hyderabad
    Mean Development Training Institute in Hyderabad

    ReplyDelete
  8. thanks for sharing valid information and a blog post.



    Study In Germany

    ReplyDelete
  9. Thanks for sharing valuable post with us .
    Java Training in Solapur

    ReplyDelete
  10. Embroidered QR Code Patch for Rick Roll Designs with Custom Stitching and Scannable Apparel Applications Online
    Explore embroidered QR code patches featuring Rick Roll-inspired designs, custom stitching, and scannable patterns. Learn whether QR codes can be embroidered and discover techniques for stitching QR designs successfully. Create unique patches for shirts, jackets, hats, backpacks, and gifts with personalized artwork and interactive QR code functionality.

    ReplyDelete