Removing spaces at the end of a string in java [duplicate]
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Strip Leading and Trailing Spaces From Java String When I import data to an application I need to get rid of the spaces at the end of certain strings but not those at the beginning, so I can't use trim()... I've set up a method: public static String quitarEspaciosFinal(String cadena) { String[] trozos = cadena.split(" "); String ultimoTrozo = trozos[trozos.length-1]; return cadena.substring(0,cadena.lastIndexOf