субота, 16 квітня 2016 р.

java palindrome function

/**
 * Checks if given <code>text</code> is a palindrome.
 *
 * @param text any string
 * @return <code>true</code> when <code>text</code> is a palindrome, <code>false</code> otherwise
 */
public static boolean isPalindrome(String text) {
String tmp = text.toLowerCase().replaceAll("[^a-zа-я0-9]", "");
StringBuilder t =  new StringBuilder(tmp).reverse();
return tmp.equals(t.toString());
}

Немає коментарів:

Дописати коментар