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
2010-08-06 06:38:31
I guess that "without using API'S" means: without using for example `StringBuilder.reverse()`.
Jesper
2010-08-06 13:07:30
+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
2010-08-06 06:38:41
+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
2010-08-06 06:45:54