Hey, Guys. Today i am going to show you How you can check if a string is palindrome.
what is palindrome?
Suppose you have a string mom
. Now if you reverse this string you get mom
again. So this is a palindrome string.
Solution
public boolean isPalindrome(String str){
char[] arr=str.toCharArray();
int i=0;
int j=arr.length-1;
while(i<j){
char temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
i++;
j--;
}
return str.equals(new String(arr));
}
Hope this helps you. Thank you ❤.
Top comments (0)