Java tutorial
//package com.java2s; import android.support.annotation.Nullable; import java.util.Arrays; import java.util.List; public class Main { @Nullable private static String removePunctuation(@Nullable String pWord) { if (pWord == null || pWord.isEmpty()) return pWord; String mResult = pWord; String[] mPunctuation = new String[] { ".", ",", ";", ":", "?", "!", "(", ")" }; List<String> mPunctuationList = Arrays.asList(mPunctuation); while (mResult.length() > 0 && mPunctuationList.contains(mResult.substring(mResult.length() - 1))) { mResult = mResult.substring(0, mResult.length() - 1); } while (mResult.length() > 0 && mPunctuationList.contains(mResult.substring(0, 1))) { mResult = mResult.substring(1, mResult.length()); } return mResult; } }