Tenho esta dúvida e não percebo o que faz o seguinte código:
return indiceInicio < indiceFim ?texto.substring(indiceInicio, indiceFim + 1): “”;
Trata-se de uma rotina para limpar os espaços, ex: " Bom dia Pessoal " ---------> “Bom dia Pessoal” ( ou seja, só retira os espaços antes e depois da frase em si)
A rotina completa é:
public static String removeEspacos(String texto){int indiceInicio = 0; while(indiceInicio < texto.length() && texto.charAt(indiceInicio) == ' ' ){ indiceInicio ++; } int indiceFim = texto.length() - 1; while(indiceFim >= 0 && texto.charAt(indiceFim) == ' ' ){ indiceFim --; } return indiceInicio < indiceFim ? texto.substring(indiceInicio, indiceFim + 1) : ""; }</blockquote>