How to order a list by a columm (java)

Let's imagine in a page called PartilhaGeral, that you have a List<> for type Partilhageral.Table_1

List<Partilhageral.Table_1> tablePart = new ArrayList<Partilhageral.Table_1>();

Steps to fill in you controller to order the list:

using lambda
tablePart.sort(Comparator.comparing(Partilhageral.Table_1::getEstado))

or

//In import reserved area:
import java.util.Collections;
import java.util.Comparator;

//In reserved code area after the set ot tablePart list add:
Collections.sort(tablePart,new SortbyStatus());

//At the end of your controller in custom_actions area add this class:
class SortbyStatus implements Comparator<Partilha.Table_1> {
        public int compare(Partilhageral.Table_1 a, Partilhageral.Table_1 b) {
            return b.getEstado() - a.getEstado();
        }
}

Last updated