How to sort a list in alphabetical order? [duplicate]

2

I have List<ListaUsuarios> and I want to sort it alphabetically by name

My code is like this

User class:

public class Usuario{
   private String nome;
   private String empresa;
   private int    idade;
   private String email;

   public Usuario(String nome, String empresa, int idade, String email){
       this.nome    = nome;
       this.empresa = empresa;
       this.idade   = idade;
       this.email   = email;
   }

   //...GETs E SETs PARA TODAS AS VARIAVEIS GLOBAIS . . .
}

class UserList:

public class ListaUsuario{
    private Usuario user;
    private int     codigo;
    private int     nivel;
    private boolean ativo;


    public ListaUsuario(Usuario user, int codigo, int nivel, boolean ativo){
        this.user   = user;
        this.codigo = codigo;
        this.nivel  = nivel;
        this.ativo  = ativo;
    }

   //...GETs e SETs PARA TODAS AS VARIAVEIS GLOBAIS . . .
}

I create my List this way: List<ListaUsuario> = new Arraylist<>();

After this populate it with N items of type ListaUsuario

How can I sort it alphabetically by user name?

    
asked by anonymous 13.11.2017 / 19:54

1 answer

-1

You should want something similar like this example I believe

import java.util.Arrays;
import java.util.Collections;    

public class HashtableDemo {

  public static void main(String args[]) {
    String[] companies = { "Yahoo", "Vodafone", "Samsung" };

      System.out.println("Array de String Ordenada em Ordem Crescente: ");
      printNumbers(companies);
  }
}

Your output will be as below

Samsung
Vodafone
Yahoo
    
13.11.2017 / 20:01