0
I have a Spring Framework project, and I need to alphabetize my list, and I have no idea how to do it. At first I managed to load the list, but it has to have that order. Please, how should I do?
@GET
@Path("/tipos-debitos")
@Produces(MediaType.APPLICATION_JSON)
@Permission(grupo = {Grupo.ADMINISTRADOR})
public Response listarDebitosMultas() {
final TipoDebitoMultaTO to = new TipoDebitoMultaTO();
try {
Arrays.asList(TipoDebitoMulta.values()).forEach(tipoDebito -> {
final br.gov.pe.tce.spj.data.transfer.TipoDebitoMulta dataTransfer = new br.gov.pe.tce.spj.data.transfer.TipoDebitoMulta();
dataTransfer.setId(tipoDebito.getCodigo());
dataTransfer.setNome(tipoDebito.getDescricao());
to.adicionar(dataTransfer);
});
final Header retorno = this.restMessageHelp.montarBaseHeader("", TipoMessage.SUCCESS);
to.setHeader(retorno);
} catch (final Exception e) {
LOGGER.error(e.getLocalizedMessage());
return Response.serverError().build();
}
return Response.ok(to, MediaType.APPLICATION_JSON).build();
}
The list is being loaded into the variable TipoDebitoMulta.values()
.
I know there is the use lambda Java 8 called, I tried to use so:
Collections.sort(TipoDebitoMulta.values());
But I was unsuccessful and made a mistake.
Thank you so much, ball show, it worked.... you saved my life!
– wladyband