Java tutorial
//package com.java2s; public class Main { private static int getEndIndex(CharSequence input) { int index = input.length() - 1; while (Character.isWhitespace(input.charAt(index))) { --index; if (index < 0) { break; } } return index; } }