tags:

views:

138

answers:

3

hi I need a detail code in java to check string palindrome without using API'S

+6  A: 
String palindrome = "..." // from elsewhere
boolean isPalindrome = palindrome.equals(new StringBuilder(palindrome).reverse().toString());
Noel M
I guess that "without using API'S" means: without using for example `StringBuilder.reverse()`.
Jesper
+1  A: 

Noel's solution is actually better. But if it's for homework, you might want to do this:

public static boolean isPalindrome(String word) {
    int left = 0;
    int right = word.length() -1;

    while (left < right) {
        if (word.charAt(left) != word.charAt(right)) 
            return false;

        left++;
        right--;
    }

    return true;
}
TTT
+2  A: 
public boolean checkPalindrome(string word){

for(int i=0 ; i < word.length()/2;i++)
{
  if(word.charAt(i) ! = word.charAt(word.length()-1-i))

      return false;
}

return true;
}
Egalitarian