Java tutorial
//package com.java2s; import android.text.TextUtils; public class Main { private static String clearLastSpace(String txt) { if (TextUtils.isEmpty(txt)) { return txt; } return txt.replaceAll("( )*$", ""); } }