Android examples for java.lang:String Search
find Last Word Index
public class Main { public static final String WHITESPACE = "\\s+"; public static int findLastWordIndex(CharSequence sentence) { boolean lastWordFound = false; for (int i = sentence.length() - 1; i >= 0; i--) { if (String.valueOf(sentence.charAt(i)).matches(WHITESPACE)) { if (lastWordFound) { return i + 1; }//from ww w . j a va2 s. co m } else { lastWordFound = true; } } return 0; } }