find if inputString is a Palindrome - Java java.lang

Java examples for java.lang:String Algorithm

Description

find if inputString is a Palindrome

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String inputString = "java2s.com";
        System.out.println(isPalindrome(inputString));
    }/*from   www  .j a va  2  s .  c o m*/

    /***
     * isPalindrom(final String  inputString)
     * API to find if inputString is a Palindrome
     * @param inputString
     * @return boolean
     */
    public static boolean isPalindrome(final String inputString) {
        final char inputStringChar[] = inputString.toCharArray();
        final int length = (inputString.length());
        for (int i = 0; i < length / 2; i++) {
            if (inputStringChar[i] != inputStringChar[length - i - 1])
                return false;
        }
        return true;
    }
}

Related Tutorials