BAEL-1525: Article code completed.

This commit is contained in:
shouvikbhattacharya
2018-02-04 18:22:17 +05:30
parent ff76cbc1fe
commit 581e8592ae
2 changed files with 51 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
package com.baeldung.string;
public class Palindrome {
public boolean isPalindrome(String text) {
text = text.replaceAll("\\s+", "").toLowerCase();
int length = text.length();
int forward = 0;
int backward = length - 1;
boolean palindrome = true;
while ((backward > forward)?(palindrome=(text.charAt(forward++) == text.charAt(backward--))):false);
return palindrome;
}
}