Skip to content

Instantly share code, notes, and snippets.

@rjlutz rjlutz/Palindrome Utility
Last active Aug 15, 2018

What would you like to do?
Bits to build a palindrome app, class with static method that tests a string to see if its a palindrome
public class Palindrome {
public static boolean check(String _s) {
return check(_s, 0, _s.length()-1);
private static boolean check(String _s, int _start, int _end) {
// base case
if (_start >= _end) return true;
// do some work
char downcaseStart = Character.toLowerCase(_s.charAt((_start)));
char downcaseEnd = Character.toLowerCase(_s.charAt(_end));
if (downcaseStart != downcaseEnd) return false;
// call simpler version
return check(_s, (_start)+1, _end-1);
TextWatcher textWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
public void afterTextChanged(Editable editable) {
String entered = input.getText().toString();
if (Palindrome.check(entered)) {
Log.v(TAG, "is a palindrome");
} else {
Log.v(TAG, "is not a palindrome");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.